[Haskell-cafe] Serialising types with existential data constructors

Ralf Lammel Ralf.Lammel at microsoft.com
Wed Sep 13 11:57:07 EDT 2006

> I start wondering, how OO languages solve the same problem.

Conceptually, what is needed is a mapping of the "head" of the input to a type. This is indeed a recurring problem in OO languages; think of object serialization or XML/Object mapping. One common way of accomplishing the mapping is to associate custom attributes (aka annotations) with classes that exactly define "when you see this element tag, instantiate this class". It is then the task of a compile-time or run-time reflection to gather these attributes and generate code from it -- code that actually constructs instances according to the mapping and the input.

Klaus Ostermann and I allude to this non-trivial extensibility problem in our GPCE 2006 paper and we started to look into ways (not in that paper) to resolve the problem in a principled way.


> -----Original Message-----
> From: haskell-cafe-bounces at haskell.org [mailto:haskell-cafe-
> bounces at haskell.org] On Behalf Of Misha Aizatulin
> Sent: Wednesday, September 13, 2006 8:13 AM
> To: haskell-cafe at haskell.org
> Subject: RE: Re: [Haskell-cafe] Serialising types with existential data
> constructors
> 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
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list