From: ralf Date: Thu, 24 Jul 2003 16:24:22 +0000 (+0000) Subject: [project @ 2003-07-24 16:24:21 by ralf] X-Git-Tag: nhc98-1-18-release~572 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=f585ec83993ec264fb3911ef0c4d69c150ef63be;p=ghc-base.git [project @ 2003-07-24 16:24:21 by ralf] Addressed Ross' concerns as follows: Included all of Data/Types.hs into Data/Typeable.hs. It really makes sense there anyway. --- diff --git a/Data/Generics/Shortcuts.hs b/Data/Generics/Shortcuts.hs index 4656b28..11ff84c 100644 --- a/Data/Generics/Shortcuts.hs +++ b/Data/Generics/Shortcuts.hs @@ -26,7 +26,6 @@ module Data.Generics.Shortcuts ( import Data.Generics.Basics import Data.Generics.Aliases import Data.Generics.Types -import Data.Types ----------------------------------------------------------------------------- diff --git a/Data/Generics/Types.hs b/Data/Generics/Types.hs index 0495d39..d97d49d 100644 --- a/Data/Generics/Types.hs +++ b/Data/Generics/Types.hs @@ -25,7 +25,6 @@ module Data.Generics.Types ( ------------------------------------------------------------------------------ -import Data.Types import Data.Generics.Basics import Data.Generics.Aliases import Data.Generics.Counts diff --git a/Data/Typeable.hs b/Data/Typeable.hs index cc45ee7..c224fdd 100644 --- a/Data/Typeable.hs +++ b/Data/Typeable.hs @@ -40,22 +40,20 @@ module Data.Typeable mkFunTy, -- :: TypeRep -> TypeRep -> TypeRep applyTy, -- :: TypeRep -> TypeRep -> Maybe TypeRep - -- - -- let fTy = mkTyCon "Foo" in show (mkAppTy (mkTyCon ",,") - -- [fTy,fTy,fTy]) - -- - -- returns "(Foo,Foo,Foo)" - -- - -- The TypeRep Show instance promises to print tuple types - -- correctly. Tuple type constructors are specified by a - -- sequence of commas, e.g., (mkTyCon ",,,,") returns - -- the 5-tuple tycon. + -- * Types as values + TypeVal, -- view type "a" as "a -> ()" + typeVal, -- :: TypeVal a + typeValOf, -- :: a -> TypeVal a + undefinedType, -- :: TypeVal a -> a + withType, -- :: a -> TypeVal a -> a + argType, -- :: (a -> b) -> TypeVal a + resType, -- :: (a -> b) -> TypeVal b + TypeFun -- functions on types ) where import qualified Data.HashTable as HT -import Data.Types import Data.Maybe import Data.Either import Data.Int @@ -101,6 +99,7 @@ import NHC.IOExtras (IORef,newIORef,readIORef,writeIORef,unsafePerformIO) -- ------------------------------------------------------------- + -- | A concrete representation of a (monomorphic) type. 'TypeRep' -- supports reasonably efficient equality. data TypeRep = TypeRep !Key TyCon [TypeRep] @@ -118,6 +117,16 @@ instance Eq TyCon where #endif + -- + -- let fTy = mkTyCon "Foo" in show (mkAppTy (mkTyCon ",,") + -- [fTy,fTy,fTy]) + -- + -- returns "(Foo,Foo,Foo)" + -- + -- The TypeRep Show instance promises to print tuple types + -- correctly. Tuple type constructors are specified by a + -- sequence of commas, e.g., (mkTyCon ",,,,") returns + -- the 5-tuple tycon. ----------------- Construction -------------------- @@ -315,6 +324,65 @@ instance (Typeable a, Typeable b) => Typeable (a -> b) where (typeOf ((undefined :: (a -> b) -> b) f)) +------------------------------------------------------------- +-- +-- Types as values +-- +------------------------------------------------------------- + +{- + +This group provides a style of encoding types as values and using +them. This style is seen as an alternative to the pragmatic style used +in Data.Typeable.typeOf and elsewhere, i.e., simply use an "undefined" +to denote a type argument. This pragmatic style suffers from lack +of robustness: one feels tempted to pattern match on undefineds. +Maybe Data.Typeable.typeOf etc. should be rewritten accordingly. + +-} + + +-- | Type as values to stipulate use of undefineds +type TypeVal a = a -> () + + +-- | The value that denotes a type +typeVal :: TypeVal a +typeVal = const () + + +-- | Map a value to its type +typeValOf :: a -> TypeVal a +typeValOf _ = typeVal + + +-- | Stipulate this idiom! +undefinedType :: TypeVal a -> a +undefinedType _ = undefined + + +-- | Constrain a type +withType :: a -> TypeVal a -> a +withType x _ = x + + +-- | The argument type of a function +argType :: (a -> b) -> TypeVal a +argType _ = typeVal + + +-- | The result type of a function +resType :: (a -> b) -> TypeVal b +resType _ = typeVal + + +-- Type functions, +-- i.e., functions mapping types to values +-- +type TypeFun a r = TypeVal a -> r + + + ------------------------------------------------------- -- -- Generate Typeable instances for standard datatypes diff --git a/Data/Types.hs b/Data/Types.hs deleted file mode 100644 index cca5789..0000000 --- a/Data/Types.hs +++ /dev/null @@ -1,79 +0,0 @@ ------------------------------------------------------------------------------ --- | --- Module : Data.Types --- Copyright : (c) The University of Glasgow 2001 --- License : BSD-style (see the file libraries/base/LICENSE) --- --- Maintainer : libraries@haskell.org --- Stability : experimental --- Portability : portable --- --- This module provides a style of encoding types as values and using --- them. This style is seens as an alternative to the pragmatic style --- used in Data.Typeable and elsewhere, i.e., simply use an undefined --- to denote a type argument. This pragmatic style suffers from lack --- of robustness: one fells tempted to pattern match on undefineds. --- ------------------------------------------------------------------------------ - -module Data.Types - ( - - -- * Types as values - TypeVal, -- view type "a" as "a -> ()" - typeVal, -- :: TypeVal a - typeValOf, -- :: a -> TypeVal a - undefinedType, -- :: TypeVal a -> a - withType, -- :: a -> TypeVal a -> a - argType, -- :: (a -> b) -> TypeVal a - resType, -- :: (a -> b) -> TypeVal b - TypeFun -- functions on types - - ) where - - -------------------------------------------------------------- --- --- Types as values --- -------------------------------------------------------------- - - --- Type as values to stipulate use of undefineds -type TypeVal a = a -> () - - ---- The value that denotes a type -typeVal :: TypeVal a -typeVal = const () - - --- Map a value to its type -typeValOf :: a -> TypeVal a -typeValOf _ = typeVal - - --- Stipulate this idiom! -undefinedType :: TypeVal a -> a -undefinedType _ = undefined - - --- Constrain a type -withType :: a -> TypeVal a -> a -withType x _ = x - - --- The argument type of a function -argType :: (a -> b) -> TypeVal a -argType _ = typeVal - - --- The result type of a function -resType :: (a -> b) -> TypeVal b -resType _ = typeVal - - --- Type functions, --- i.e., functions mapping types to values --- -type TypeFun a r = TypeVal a -> r