
22 Jun
2011
22 Jun
'11
11:26 a.m.
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.) Regards, Malcolm