Data.Dynamic
John Meacham
john at repetae.net
Fri Mar 4 02:25:15 EST 2005
Actually, could this patch be applied?
it also provides a routine to get the index of a typerep for efficient
hashing. It is in the IO monad because the index may change between
runs.
John
--
John Meacham - ⑆repetae.net⑆john⑈
-------------- next part --------------
Index: Dynamic.hs
===================================================================
RCS file: /cvs/fptools/libraries/base/Data/Dynamic.hs,v
retrieving revision 1.28
diff -u -r1.28 Dynamic.hs
--- Dynamic.hs 11 Jan 2005 16:04:10 -0000 1.28
+++ Dynamic.hs 4 Mar 2005 07:23:16 -0000
@@ -34,7 +34,8 @@
-- * Applying functions of dynamic type
dynApply,
- dynApp
+ dynApp,
+ dynTypeRep
) where
@@ -162,3 +163,8 @@
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
+
+
Index: Typeable.hs
===================================================================
RCS file: /cvs/fptools/libraries/base/Data/Typeable.hs,v
retrieving revision 1.34
diff -u -r1.34 Typeable.hs
--- Typeable.hs 2 Feb 2005 14:54:18 -0000 1.34
+++ Typeable.hs 4 Mar 2005 07:23:16 -0000
@@ -77,7 +77,8 @@
typeOf3Default, -- :: (Typeable4 t, Typeable a) => t a b c d -> TypeRep
typeOf4Default, -- :: (Typeable5 t, Typeable a) => t a b c d e -> TypeRep
typeOf5Default, -- :: (Typeable6 t, Typeable a) => t a b c d e f -> TypeRep
- typeOf6Default -- :: (Typeable7 t, Typeable a) => t a b c d e f g -> TypeRep
+ typeOf6Default, -- :: (Typeable7 t, Typeable a) => t a b c d e f g -> TypeRep
+ typeRepIndex
) where
@@ -652,3 +653,11 @@
appKeys :: Key -> [Key] -> Key
appKeys k ks = foldl appKey k ks
+
+-- | This can be used for creation of efficient maps or hash tables based on TypeReps.
+-- It is in IO because the numbering may differ between runs of a program.
+
+
+typeRepIndex :: TypeRep -> IO Int
+typeRepIndex (TypeRep (Key i) _ _) = return i
+
More information about the Libraries
mailing list