Commit 9cd0f821 authored by simonmar's avatar simonmar
Browse files

[project @ 2002-03-14 12:09:49 by simonmar]

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.
parent aa8f96f4
......@@ -10,7 +10,7 @@
-- 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.
--
......@@ -37,16 +37,21 @@ import GHC.Err
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
__interface "base" DataziDynamic 1 where
__export DataziDynamic Dynamic ;
data Dynamic;
......@@ -9,7 +9,7 @@
-- 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.
--
......@@ -66,6 +66,10 @@ module Data.Dynamic
import Data.Maybe
import Data.Either
import Data.Int
import Data.Word
import Foreign.Ptr
import Foreign.StablePtr
#ifdef __GLASGOW_HASKELL__
import GHC.Base
......@@ -74,7 +78,6 @@ import GHC.Err
import GHC.Num
import GHC.Float
import GHC.IOBase
import GHC.Dynamic
#endif
#ifdef __GLASGOW_HASKELL__
......@@ -87,30 +90,22 @@ unsafeCoerce = unsafeCoerce#
-- 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) =
......@@ -129,6 +124,31 @@ instance Show TypeRep where
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
......@@ -145,9 +165,6 @@ isTupleTyCon :: TyCon -> Bool
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,
......@@ -282,6 +299,19 @@ INSTANCE_TYPEABLE2(Either,eitherTc,"Either")
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")
......
......@@ -9,7 +9,7 @@
-- 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.
--
......@@ -27,11 +27,3 @@ module Data.Int
#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")
......@@ -9,7 +9,7 @@
-- 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.
--
......@@ -28,11 +28,3 @@ module Data.Word
#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")
......@@ -9,7 +9,7 @@
-- 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.
--
......@@ -40,8 +40,6 @@ module Foreign.Ptr (
) where
import Data.Dynamic
#ifdef __GLASGOW_HASKELL__
import GHC.Ptr
import GHC.IOBase
......@@ -71,6 +69,3 @@ instance Show (Ptr a) where
foreign import "freeHaskellFunctionPtr" unsafe
freeHaskellFunPtr :: FunPtr a -> IO ()
#include "Dynamic.h"
INSTANCE_TYPEABLE1(Ptr,ptrTc,"Ptr")
......@@ -9,7 +9,7 @@
-- 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.
--
......@@ -24,12 +24,7 @@ module Foreign.StablePtr
, 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")
% -----------------------------------------------------------------------------
% $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
%
......@@ -20,7 +20,7 @@ import Data.Maybe ( Maybe(..) )
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
%
......@@ -18,8 +18,7 @@ module GHC.Stable
, castPtrToStablePtr -- :: Ptr () -> StablePtr a
) where
import Foreign.Ptr
import GHC.Ptr
import GHC.Base
import GHC.IOBase
......
......@@ -9,7 +9,7 @@
-- 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.
--
......@@ -112,22 +112,8 @@ import GHC.Read
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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment