X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Data%2FDynamic.hs;h=933224c9e32c55fbc82ff6efa3ce91f6ad0e235d;hb=052b9b84fff4bffabbd93d19cb17a2c6c6672128;hp=31c0199adbf799644466993e00c6af6e9bfdf6dc;hpb=0a913ae5534cd8d3532c090054f482584bc6a0c3;p=ghc-base.git diff --git a/Data/Dynamic.hs b/Data/Dynamic.hs index 31c0199..933224c 100644 --- a/Data/Dynamic.hs +++ b/Data/Dynamic.hs @@ -1,4 +1,4 @@ -{-# OPTIONS -fno-implicit-prelude #-} +{-# OPTIONS_GHC -fno-implicit-prelude #-} ----------------------------------------------------------------------------- -- | -- Module : Data.Dynamic @@ -34,7 +34,8 @@ module Data.Dynamic -- * Applying functions of dynamic type dynApply, - dynApp + dynApp, + dynTypeRep ) where @@ -64,10 +65,10 @@ unsafeCoerce = unsafeCoerce# #ifdef __NHC__ import NonStdUnsafeCoerce (unsafeCoerce) import NHC.IOExtras (IORef,newIORef,readIORef,writeIORef,unsafePerformIO) -#else -#include "Typeable.h" #endif +#include "Typeable.h" + ------------------------------------------------------------- -- -- The type Dynamic @@ -88,9 +89,7 @@ import NHC.IOExtras (IORef,newIORef,readIORef,writeIORef,unsafePerformIO) data Dynamic = Dynamic TypeRep Obj #endif -#ifndef __NHC__ INSTANCE_TYPEABLE0(Dynamic,dynamicTc,"Dynamic") -#endif instance Show Dynamic where -- the instance just prints the type representation. @@ -143,7 +142,7 @@ fromDyn (Dynamic t v) def fromDynamic :: Typeable a => Dynamic -- ^ the dynamically-typed object - -> Maybe a -- ^ returns: @'Just' a@, if the dyanmically-typed + -> Maybe a -- ^ returns: @'Just' a@, if the dynamically-typed -- object has the correct type (and @a@ is its value), -- or 'Nothing' otherwise. fromDynamic (Dynamic t v) = @@ -164,3 +163,6 @@ dynApp f x = case dynApply f x of Nothing -> error ("Type error in dynamic application.\n" ++ "Can't apply function " ++ show f ++ " to argument " ++ show x) + +dynTypeRep :: Dynamic -> TypeRep +dynTypeRep (Dynamic tr _) = tr