escape from existential quantification

Hal Daume III hdaume@ISI.EDU
Thu, 27 Feb 2003 13:01:31 -0800 (PST)

> It occasionally happens that I *know* what type is (or at least ought to be) inside
> an existential type, but unfortunately GHC doesn't, and I need to get the value out.
> This can be solved using dynamic types, for example you declare the datatype as

You can also use an unsafe cast operation if you know statically what the
type will be, but the compiler doesn't.  See for example for an example of
this.  It essentially has a function which writes items of arbitrary type
(in a list) to a binary memory location and then reads the back.  When
reading them back, the only way to know the type is to look at the type of
the corresponding item on the "write" list.  It relies on this to make the
casting really a safe operation.