<div>Hi,</div><div><br></div><div>Suppose I have the following types:</div><div><br></div>> data Expr expr = Lit Nat | Add (expr, expr)<div>> newtype Fix f = Fix {unFix :: f (Fix f)}</div><div><br></div><div>I can construct a sample term:</div>
<div><br></div><div>> term :: Expr (Expr (Expr expr))</div><div>> term = Add (Lit 1, Add (Lit 2, Lit 3))</div><div><br></div><div>But isn't quite what I need. What I really need is:</div><div><br></div><div>> term' :: Fix Expr</div>
<div>> term' = Fix . Add $ (Fix . Lit $ 1, Fix . Add $ (Fix . Lit $ 2, Fix . Lit $ 3))</div><div><br></div><div>I feel like there's a stupidly simple way to automatically produce term' from term, but I'm not seeing it.</div>
<div><br></div><div>Any ideas?</div><div><br></div><div>Best,</div><div>Sebastien</div>