[Haskell-beginners] Easier alternatives to existential types?

Emile Melnicov erm.dot.at at gmail.com
Thu Nov 26 13:01:32 EST 2009


> Well, yes, I know that almost certanly that was not what you 
> were thinking when you wrote the question.

Sorry, I should include my code snippet indeed.

data Chunk a = Chunk { cHeader :: Header, cData :: a }
data Header = Header { hID :: Word32, hSize :: Word32 }
data Format = Format { ... }
newtype Data = Data ByteString

h :: Header
...
formatChunk :: Chunk Format
...
dataChunk :: Chunk Data
...

data Container a =
    Container { ctHeader :: Header, ctType :: Word32,
                ctContent :: [Chunk a] }

-- Very naive.
containerChunk :: Container a
containerChunk = Container h 42 [formatChunk, dataChunk]

I'm interested in common pattern used in Haskell for this kind 
of problems.

> If you really want existentials, though, I'd recommend using 
> GADT syntax

OK, I'll try it out. I'm already know about GADT's, but can't 
catch the difference between regular Algebraic Data Types and 
Generalised ones (in terms of disjoint union etc.). Can you 
recommend some paper where GADT's are described, but without 
very deep mathematical entities?


More information about the Beginners mailing list