[Haskell-cafe] Interleaving type variables in a tree, has this a name ?

Eric Dedieu papa.eric at free.fr
Sun Oct 14 22:45:10 CEST 2012

>>> data ANode a b = ANode a [BNode a b] [BNode a b]
>>> data BNode a b = BNode b [ANode a b] [ANode a b]
> Wouldn't the following work as well and be simpler to handle :
>> data Node a b = Node a [Node b a] [Node b a]

Yes !

In fact my actual structure is not symmetrical (some lists must
preserve order and store additional information for that, some not,
and one is a Maybe), so I "naturally" used two distinct node types.
When I simplified it for the post, it became symmetrical...

Yet I think you're right: if I made it symmetrical (and more general),
I would gain much by using your suggestion (and I could also define
e.g. Foldable (Node a) which would nicely work a all levels).


More information about the Haskell-Cafe mailing list