[Haskell-cafe] Fixed point newtype confusion

Sebastien Zany sebastien at chaoticresearch.com
Sun May 6 14:59:59 CEST 2012


Hi,

Suppose I have the following types:

> data Expr expr = Lit Nat | Add (expr, expr)
> newtype Fix f = Fix {unFix :: f (Fix f)}

I can construct a sample term:

> term :: Expr (Expr (Expr expr))
> term = Add (Lit 1, Add (Lit 2, Lit 3))

But isn't quite what I need. What I really need is:

> term' :: Fix Expr
> term' = Fix . Add $ (Fix . Lit $ 1, Fix . Add $ (Fix . Lit $ 2, Fix . Lit
$ 3))

I feel like there's a stupidly simple way to automatically produce term'
from term, but I'm not seeing it.

Any ideas?

Best,
Sebastien
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120506/57746f61/attachment.htm>


More information about the Haskell-Cafe mailing list