The ghc documentation for the Dynamic library says:

"Examples where this library may come in handy (dynamic types, really -
hopefully the library provided here will suffice) are: persistent programming,
..."                                                   ^^^^^^^^^^ ^^^^^^^^^^^

I would like to store a data structure in a file (perhaps using mmalloc), and
store a TypeRep with it, so that when opening the file later, I can verify that
it is what I think it is. I would also like to be able to extract the contents
of the file as a Dynamic.

To do this would require several things the current Dynamic library lacks:

(i) A way to store a TypeRep. TypeRep is an instance of Show. If it were also an
instance of Read, such that read . show == id, a TypeRep could be stored as a
string. I would write my own instance, but I am a little daunted by the
mechanics of the Read class, and worried about ensuring that read . show == id,
not being the author or maintainer of the Show instance.

(ii) To be able to construct a Dynamic from a TypeRep and a concrete type
i.e. some form of access to the Dynamic constructor. The concrete type need not
range over typical Haskell instances of Typeable, since they work with toDyn
anyway. But something is needed for things like Addr and ForeignObj, which
cannot be instances of Typeable.

(iii) dynType :: Dynamic -> TypeRep
Of course one can repeatedly apply fromDynamic at different types, but there
could be a large number of possible types. Even worse, some polymorphic code
might wish to know only the top-level type constructor.

Obviously (ii) and (iii) are easy enough to hack into the current
implementation, but it would be better to add something that most people agree
with.

As for (i), perhaps it would be relatively easy for one of the Glasgow Hackers
to add ?

Tim

Reply via email to