[Haskell-cafe] Why aren't there anonymous sum types in Haskell?
malcolm.wallace at me.com
Wed Jun 22 13:26:56 CEST 2011
Why not just do what we do for tuples? Define a bunch of generic types up front:
data Choice2 a b = OneOf2 a | TwoOf2 b
data Choice3 a b c = OneOf3 a | TwoOf3 b | ThreeOf3 c
The module Text.XML.HaXml.OneOfN defines these types up to size 20.
The package HaXml also comes with a small command-line driven generator tool (called MkOneOf) that can automatically write you a OneOfN type (or set of types) of arbitrary finite size.
(Being part of HaXml, it also generates instances of some XML reading/writing classes as well.)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe