-- | Highly random utility functions
module Util (
-- * Flags dependent on the compiler build
- ghciSupported, debugIsOn, ghciTablesNextToCode, picIsOn,
+ ghciSupported, debugIsOn, ghciTablesNextToCode, isDynamicGhcLib,
isWindowsHost, isWindowsTarget, isDarwinTarget,
-- * General list processing
isIn, isn'tIn,
+ -- * Tuples
+ fstOf3, sndOf3, thirdOf3,
+
-- * List operations controlled by another list
takeList, dropList, splitAtList, split,
dropTail,
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)
import Control.Concurrent.MVar ( MVar, newMVar, newEmptyMVar )
#ifdef DEBUG
-import qualified Data.List as List ( elem, notElem )
import FastTypes
#endif
ghciTablesNextToCode = False
#endif
-picIsOn :: Bool
-#ifdef __PIC__
-picIsOn = True
+isDynamicGhcLib :: Bool
+#ifdef DYNAMIC
+isDynamicGhcLib = True
#else
-picIsOn = False
+isDynamicGhcLib = False
#endif
isWindowsHost :: Bool
nTimes n f = f . nTimes (n-1) f
\end{code}
+\begin{code}
+fstOf3 :: (a,b,c) -> a
+sndOf3 :: (a,b,c) -> b
+thirdOf3 :: (a,b,c) -> c
+fstOf3 (a,_,_) = a
+sndOf3 (_,b,_) = b
+thirdOf3 (_,_,c) = c
+\end{code}
+
%************************************************************************
%* *
\subsection[Utils-lists]{General list processing}
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}
+