Eliminate some orphan-instance modules to speed up compilation.
I decided to just bite the bullet and give Data.Dynamic an .hi-boot
file, so I could remove GHC.Dynamic altogether, move its data types
into Data.Dynamic and hence prevent Data.Dynamic from being an orphan
module. Furthermore, GHC.Dynamic wasn't GHC specific - its only
purpose in life was to prevent module loops, so having it at all was
artificial.
-- Stability : experimental
-- Portability : portable
--
--- $Id: Fix.hs,v 1.2 2001/07/03 11:37:49 simonmar Exp $
+-- $Id: Fix.hs,v 1.3 2002/03/14 12:09:49 simonmar Exp $
--
-- The Fix monad.
--
import Data.Maybe
#endif
+import System.IO
+
fix :: (a -> a) -> a
fix f = let x = f x in x
class (Monad m) => MonadFix m where
mfix :: (a -> m a) -> m a
--- Perhaps these should live beside (the ST & IO) definition.
instance MonadFix Maybe where
mfix f = let
a = f $ case a of
Just x -> x
_ -> error "empty mfix argument"
in a
+
+instance MonadFix IO where
+ mfix = fixIO
+
--- /dev/null
+__interface "base" DataziDynamic 1 where
+__export DataziDynamic Dynamic ;
+data Dynamic;
-- Stability : experimental
-- Portability : portable
--
--- $Id: Dynamic.hs,v 1.4 2001/12/21 15:07:21 simonmar Exp $
+-- $Id: Dynamic.hs,v 1.5 2002/03/14 12:09:49 simonmar Exp $
--
-- The Dynamic interface provides basic support for dynamic types.
--
import Data.Maybe
import Data.Either
+import Data.Int
+import Data.Word
+import Foreign.Ptr
+import Foreign.StablePtr
#ifdef __GLASGOW_HASKELL__
import GHC.Base
import GHC.Num
import GHC.Float
import GHC.IOBase
-import GHC.Dynamic
#endif
#ifdef __GLASGOW_HASKELL__
-- The dynamic type is represented by Dynamic, carrying
-- the dynamic value along with its type representation:
--- the instance just prints the type representation.
+data Dynamic = Dynamic TypeRep Obj
+
instance Show Dynamic where
+ -- the instance just prints the type representation.
showsPrec _ (Dynamic t _) =
showString "<<" .
showsPrec 0 t .
showString ">>"
--- Operations for going to and from Dynamic:
-
-toDyn :: Typeable a => a -> Dynamic
-toDyn v = Dynamic (typeOf v) (unsafeCoerce v)
-
-fromDyn :: Typeable a => Dynamic -> a -> a
-fromDyn (Dynamic t v) def
- | typeOf def == t = unsafeCoerce v
- | otherwise = def
-
-fromDynamic :: Typeable a => Dynamic -> Maybe a
-fromDynamic (Dynamic t v) =
- case unsafeCoerce v of
- r | t == typeOf r -> Just r
- | otherwise -> Nothing
+data Obj = Obj
+ -- dummy type to hold the dynamically typed value.
--- (Abstract) universal datatype:
+data TypeRep
+ = App TyCon [TypeRep]
+ | Fun TypeRep TypeRep
+ deriving ( Eq )
instance Show TypeRep where
showsPrec p (App tycon tys) =
showParen (p > 8) $
showsPrec 9 f . showString " -> " . showsPrec 8 a
+-- type constructors are
+data TyCon = TyCon Int String
+
+instance Eq TyCon where
+ (TyCon t1 _) == (TyCon t2 _) = t1 == t2
+
+instance Show TyCon where
+ showsPrec _ (TyCon _ s) = showString s
+
+-- Operations for going to and from Dynamic:
+
+toDyn :: Typeable a => a -> Dynamic
+toDyn v = Dynamic (typeOf v) (unsafeCoerce v)
+
+fromDyn :: Typeable a => Dynamic -> a -> a
+fromDyn (Dynamic t v) def
+ | typeOf def == t = unsafeCoerce v
+ | otherwise = def
+
+fromDynamic :: Typeable a => Dynamic -> Maybe a
+fromDynamic (Dynamic t v) =
+ case unsafeCoerce v of
+ r | t == typeOf r -> Just r
+ | otherwise -> Nothing
+
-- To make it possible to convert values with user-defined types
-- into type Dynamic, we need a systematic way of getting
-- the type representation of an arbitrary type. A type
isTupleTyCon (TyCon _ (',':_)) = True
isTupleTyCon _ = False
-instance Show TyCon where
- showsPrec _ (TyCon _ s) = showString s
-
-- If we enforce the restriction that there is only one
-- @TyCon@ for a type & it is shared among all its uses,
-- we can map them onto Ints very simply. The benefit is,
INSTANCE_TYPEABLE1(IO,ioTc,"IO")
INSTANCE_TYPEABLE1(Maybe,maybeTc,"Maybe")
INSTANCE_TYPEABLE0(Ordering,orderingTc,"Ordering")
+INSTANCE_TYPEABLE0(Handle,handleTc,"Handle")
+INSTANCE_TYPEABLE1(Ptr,ptrTc,"Ptr")
+INSTANCE_TYPEABLE1(StablePtr,stablePtrTc,"StablePtr")
+
+INSTANCE_TYPEABLE0(Int8,int8Tc, "Int8")
+INSTANCE_TYPEABLE0(Int16,int16Tc,"Int16")
+INSTANCE_TYPEABLE0(Int32,int32Tc,"Int32")
+INSTANCE_TYPEABLE0(Int64,int64Tc,"Int64")
+
+INSTANCE_TYPEABLE0(Word8,word8Tc, "Word8" )
+INSTANCE_TYPEABLE0(Word16,word16Tc,"Word16")
+INSTANCE_TYPEABLE0(Word32,word32Tc,"Word32")
+INSTANCE_TYPEABLE0(Word64,word64Tc,"Word64")
INSTANCE_TYPEABLE0(TyCon,tyconTc,"TyCon")
INSTANCE_TYPEABLE0(TypeRep,typeRepTc,"TypeRep")
-- Stability : experimental
-- Portability : portable
--
--- $Id: Int.hs,v 1.2 2001/07/03 11:37:49 simonmar Exp $
+-- $Id: Int.hs,v 1.3 2002/03/14 12:09:49 simonmar Exp $
--
-- Sized Integer types.
--
#ifdef __GLASGOW_HASKELL__
import GHC.Int
#endif
-
-import Data.Dynamic
-
-#include "Dynamic.h"
-INSTANCE_TYPEABLE0(Int8,int8Tc, "Int8")
-INSTANCE_TYPEABLE0(Int16,int16Tc,"Int16")
-INSTANCE_TYPEABLE0(Int32,int32Tc,"Int32")
-INSTANCE_TYPEABLE0(Int64,int64Tc,"Int64")
-- Stability : experimental
-- Portability : portable
--
--- $Id: Word.hs,v 1.2 2001/07/03 11:37:50 simonmar Exp $
+-- $Id: Word.hs,v 1.3 2002/03/14 12:09:49 simonmar Exp $
--
-- Sized unsigned integer types.
--
#ifdef __GLASGOW_HASKELL__
import GHC.Word
#endif
-
-import Data.Dynamic
-
-#include "Dynamic.h"
-INSTANCE_TYPEABLE0(Word8,word8Tc, "Word8" )
-INSTANCE_TYPEABLE0(Word16,word16Tc,"Word16")
-INSTANCE_TYPEABLE0(Word32,word32Tc,"Word32")
-INSTANCE_TYPEABLE0(Word64,word64Tc,"Word64")
-- Stability : provisional
-- Portability : portable
--
--- $Id: Ptr.hs,v 1.4 2002/02/27 14:31:44 simonmar Exp $
+-- $Id: Ptr.hs,v 1.5 2002/03/14 12:09:50 simonmar Exp $
--
-- Pointer types.
--
) where
-import Data.Dynamic
-
#ifdef __GLASGOW_HASKELL__
import GHC.Ptr
import GHC.IOBase
foreign import "freeHaskellFunctionPtr" unsafe
freeHaskellFunPtr :: FunPtr a -> IO ()
-
-#include "Dynamic.h"
-INSTANCE_TYPEABLE1(Ptr,ptrTc,"Ptr")
-- Stability : provisional
-- Portability : portable
--
--- $Id: StablePtr.hs,v 1.2 2001/07/03 11:37:50 simonmar Exp $
+-- $Id: StablePtr.hs,v 1.3 2002/03/14 12:09:50 simonmar Exp $
--
-- Stable pointers.
--
, castPtrToStablePtr -- :: Ptr () -> StablePtr a
) where
-import Data.Dynamic
-
#ifdef __GLASGOW_HASKELL__
import GHC.Stable
import GHC.Err
#endif
-
-#include "Dynamic.h"
-INSTANCE_TYPEABLE1(StablePtr,stablePtrTc,"StablePtr")
+++ /dev/null
-% -----------------------------------------------------------------------------
-% $Id: Dynamic.lhs,v 1.1 2001/06/28 14:15:03 simonmar Exp $
-%
-% (c) The University of Glasgow, 1998-2000
-%
-
-The Dynamic type is used in the Exception type, so we have to have
-Dynamic visible here. The rest of the operations on Dynamics are
-available in lang/Dynamic.lhs.
-
-\begin{code}
-{-# OPTIONS -fno-implicit-prelude #-}
-
-#ifndef __HUGS__
-module GHC.Dynamic where
-
-import GHC.Base
-#endif
-
-data Dynamic = Dynamic TypeRep Obj
-
-data Obj = Obj
- -- dummy type to hold the dynamically typed value.
-
-data TypeRep
- = App TyCon [TypeRep]
- | Fun TypeRep TypeRep
- deriving ( Eq )
-
--- type constructors are
-data TyCon = TyCon Int String
-
-instance Eq TyCon where
- (TyCon t1 _) == (TyCon t2 _) = t1 == t2
-\end{code}
% ------------------------------------------------------------------------------
-% $Id: IOBase.lhs,v 1.6 2002/02/05 17:32:26 simonmar Exp $
+% $Id: IOBase.lhs,v 1.7 2002/03/14 12:09:50 simonmar Exp $
%
% (c) The University of Glasgow, 1994-2001
%
import GHC.Show
import GHC.List
import GHC.Read
-import GHC.Dynamic
+import {-# SOURCE #-} Data.Dynamic
-- ---------------------------------------------------------------------------
-- The IO Monad
% -----------------------------------------------------------------------------
-% $Id: Stable.lhs,v 1.1 2001/06/28 14:15:03 simonmar Exp $
+% $Id: Stable.lhs,v 1.2 2002/03/14 12:09:52 simonmar Exp $
%
% (c) The GHC Team, 1992-2000
%
, castPtrToStablePtr -- :: Ptr () -> StablePtr a
) where
-import Foreign.Ptr
-
+import GHC.Ptr
import GHC.Base
import GHC.IOBase
-- Stability : provisional
-- Portability : portable
--
--- $Id: IO.hs,v 1.5 2002/02/27 14:32:23 simonmar Exp $
+-- $Id: IO.hs,v 1.6 2002/03/14 12:09:52 simonmar Exp $
--
-- The standard IO library.
--
import GHC.Show
#endif
-import Data.Dynamic
-import Control.Monad.Fix
import System.IO.Error
-- -----------------------------------------------------------------------------
--- MonadFix instance
-
-instance MonadFix IO where
- mfix = fixIO
-
--- -----------------------------------------------------------------------------
--- Typeable instance for Handle
-
-#include "Dynamic.h"
-INSTANCE_TYPEABLE0(Handle,handleTc,"Handle")
-
--- -----------------------------------------------------------------------------
-- Standard IO
putChar :: Char -> IO ()