> 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. Best, Ralf > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:haskell-cafe- > [EMAIL PROTECTED] On Behalf Of Misha Aizatulin > Sent: Wednesday, September 13, 2006 8:13 AM > To: haskell-cafe@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@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe