
22 Oct
2010
22 Oct
'10
7:24 a.m.
Forgot to reply to list
On 22 October 2010 12:14, Dan Doel
Another solution, though, is SHE. With it, you can write:
data ListF a r = NilF | ConsF a r newtype List a = Roll (ListF a (List a))
pattern Nil = Roll NilF pattern Cons x xs = Roll (ConsF x xs)
And not worry about Rolls anymore.
Ah yes, pattern synonyms. This solution is somewhat unsatisfying because you will also need some smart constructors: """ nil = Roll NilF cons x xs = Roll (ConsF x xs) """ Now the names of the smart constructors for building the data type are not the same as the things you pattern match on, which is a slightly annoying asymmetry. It's certainly less complicated than the TypeFamilies based solution though! Cheers, Max