Do you really need a gadt? Or do you just want to remove the restriction on a simple enumeration type using only null constructors? If the latter, then there are options. One of them is to use the GHC Generic mechanism along with the implementation of a suitable general enumeration class. This is available in the generic-deriving package. Here is an example:
{-
Now test is the following list:
[ Leaf False , Node (Leaf False) (Leaf False) , Leaf True , Node (Leaf False) (Node (Leaf False) (Leaf False)) , Node (Node (Leaf False) (Leaf False)) (Leaf False) , Node (Leaf False) (Leaf True) , Node (Node (Leaf False) (Leaf False)) (Node (Leaf False) (Leaf False)) , Node (Leaf True) (Leaf False),Node (Leaf False) (Node (Leaf False) (Node (Leaf False) (Leaf False))) , Node (Node (Leaf False) (Leaf False)) (Leaf True) ]
This genum implementation uses diagonalization to combine products. This ensures that each value does appear somewhere in the list, but can lead to an unexpected order.
source share