[Haskell-beginners] Easier alternatives to existential types?

Stephen Tetley stephen.tetley at gmail.com
Thu Nov 26 15:01:19 EST 2009


2009/11/26 Brent Yorgey <byorgey at seas.upenn.edu>:

> Do you *really* need 'Chunk' to be able to hold *any* type of data?
> Or are there just a few alternatives?  If there are only a few
> alternatives, you can put the alternatives together in a data type,
> like this:

Horribly enough, RIFF files do seem to support any type of data. A
processor of RIFF files would presumably parse chunk types that it
knows to expect and discard the rest.

Data.Dynamic from the Hierarchical libs shipped with GHC is another
option. Or a home brewed union type:


data Chunk = WaveChunk { ... }
           | AuChunk { ... }
           | UnintrepretedChunk ByteString

Best wishes

Stephen


More information about the Beginners mailing list