
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

On Friday 22 October 2010 7:24:37 am Max Bolingbroke wrote:
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!
SHE's pattern synonyms also work as expressions, so there's no asymmetry. They work just like constructors as far as I can tell (with what little I've played with them); you can even partially apply them (in expressions). It doesn't do infix synonyms currently, though. -- Dan

On 22 October 2010 22:06, Dan Doel
SHE's pattern synonyms also work as expressions, so there's no asymmetry. They work just like constructors as far as I can tell (with what little I've played with them); you can even partially apply them (in expressions).
I didn't realise that - pretty cool! Max
participants (2)
-
Dan Doel
-
Max Bolingbroke