[Haskell-cafe] Re: Scrap your rolls/unrolls
Max Bolingbroke
batterseapower at hotmail.com
Fri Oct 22 07:24:37 EDT 2010
Forgot to reply to list
On 22 October 2010 12:14, Dan Doel <dan.doel at gmail.com> wrote:
> 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
More information about the Haskell-Cafe
mailing list