X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2Futils%2FUtil.lhs;h=fbbe76717849e76e90affe581da81cb4383dafb2;hp=c5a826a4829a9353edc423f3952ba9e0291be861;hb=f278f0676579f67075033a4f9857715909c4b71e;hpb=ef6e8211dee59eb7fa80a242391b89b52bd57f80 diff --git a/compiler/utils/Util.lhs b/compiler/utils/Util.lhs index c5a826a..fbbe767 100644 --- a/compiler/utils/Util.lhs +++ b/compiler/utils/Util.lhs @@ -76,12 +76,16 @@ module Util ( escapeSpaces, parseSearchPath, Direction(..), reslash, + + -- * Utils for defining Data instances + abstractConstr, abstractDataType, mkNoRepType ) where #include "HsVersions.h" import Panic +import Data.Data import Data.IORef ( IORef, newIORef, atomicModifyIORef ) import System.IO.Unsafe ( unsafePerformIO ) import Data.List hiding (group) @@ -902,3 +906,29 @@ reslash d = f Backwards -> '\\' \end{code} +%************************************************************************ +%* * +\subsection[Utils-Data]{Utils for defining Data instances} +%* * +%************************************************************************ + +These functions helps us to define Data instances for abstract types. + +\begin{code} +abstractConstr :: String -> Constr +abstractConstr n = mkConstr (abstractDataType n) ("{abstract:"++n++"}") [] Prefix +\end{code} + +\begin{code} +abstractDataType :: String -> DataType +abstractDataType n = mkDataType n [abstractConstr n] +\end{code} + +\begin{code} +-- Old GHC versions come with a base library with this function misspelled. +#if __GLASGOW_HASKELL__ < 612 +mkNoRepType :: String -> DataType +mkNoRepType = mkNorepType +#endif +\end{code} +