X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=Data%2FDynamic.hs;h=761f55f150679140c66eed315cb9330d4483c5c8;hb=26d2805a6e58822d246cf9601fb226b0861e7f65;hp=f02290a4769bb31be13c9361cf034752bea0faa8;hpb=aaf764b3ad8b1816d68b5f27299eac125f08e1a5;p=haskell-directory.git diff --git a/Data/Dynamic.hs b/Data/Dynamic.hs index f02290a..761f55f 100644 --- a/Data/Dynamic.hs +++ b/Data/Dynamic.hs @@ -34,7 +34,8 @@ module Data.Dynamic -- * Applying functions of dynamic type dynApply, - dynApp + dynApp, + dynTypeRep ) where @@ -98,16 +99,14 @@ instance Show Dynamic where showString ">>" #ifdef __GLASGOW_HASKELL__ -type Obj = forall a . a - -- Dummy type to hold the dynamically typed value. +type Obj = Any + -- Use GHC's primitive 'Any' type to hold the dynamically typed value. -- - -- In GHC's new eval/apply execution model this type must - -- be polymorphic. It can't be a constructor, because then - -- GHC will use the constructor convention when evaluating it, - -- and this will go wrong if the object is really a function. On - -- the other hand, if we use a polymorphic type, GHC will use + -- In GHC's new eval/apply execution model this type must not look + -- like a data type. If it did, GHC would use the constructor convention + -- when evaluating it, and this will go wrong if the object is really a + -- function. Using Any forces GHC to use -- a fallback convention for evaluating it that works for all types. - -- (using a function type here would also work). #elif !defined(__HUGS__) data Obj = Obj #endif @@ -162,3 +161,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