[Haskell-cafe] Scrap your rolls/unrolls

Dan Doel dan.doel at gmail.com
Fri Oct 22 07:14:06 EDT 2010

On Friday 22 October 2010 6:37:49 am Max Bolingbroke wrote:
> This is all well and good, but it means when working with data types
> defined in this manner you have to write Roll and unroll everywhere.
> This is tedious :-(

Your discovery is interesting (and I haven't seen it before).

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.

-- Dan


More information about the Haskell-Cafe mailing list