Christopher Done wrote:
It's very easy to state this problem without enough details and mislead
people into providing a solution for a different problem, so I'll try to
include all the information and use-case. I need a function that can
store a value in a concrete opaque type. I know the type of the value
when I store it, and I know the type of the value when I extract it,
insofar as I know the type inclusive of a class constraint context. But
the container must store many different things at once. Given that I
know the type of the thing when I store it and when I extract it, there
ought to be a “safe’ way to do this, in the same way that Data.Dynamic
I have to ashamedly admit that I didn't read your problem description in
its entirety, but maybe my vault package can help?
In particular, the Locker stores arbitrary values like Dynamic ,
except that values are extracted and removed with the help of a Key .
This gets rid of the Typeable constraint.
Note that there is a fundamental problem with storing polymorphic types,
which is related to the "value restriction for reference types". One of
the main points of the Typable class is actually that it enforces
monomorphic types. Similarly, the vault library enforces monomorphic
types by having newKey in the IO monad.
Haskell-Cafe mailing list