[Haskell-cafe] Serialising types with existential data constructors

Misha Aizatulin avatar at hot.ee
Wed Sep 13 11:12:46 EDT 2006


Einar Karttunen wrote:
> >   I've been using existentially quantified data constructors like
> > 
> > > data Box = forall a. Cxt a => Box a
> 
> If you can include Typeable into the mix then serializing works.
> 
> Serialize the value as "<name of type> <value>".
> 
> When deserializing use a Map <name of type> <decoder-function>
> and get the appropriate decoder from there for the type in question.

  This is indeed the only solution I see so far. It has a serious
problem though: as soon as I write the mapping, I limit once and for all
the set of all types that can be used with my box. And I do so in a
non-extensible way - if someone later would like to use my box with some
other type in it, they wouldn't be able to.

  In fact, I start wondering, how OO languages solve the same problem.
I'll take a look at Java now.

Cheers,
   Misha


More information about the Haskell-Cafe mailing list