[Haskell-cafe] Wouter-style expressions
Wouter Swierstra
wss at Cs.Nott.AC.UK
Wed Jun 4 04:22:06 EDT 2008
Hi Ron,
I've attached a revised file that solves your problem.
The solution is actually quite subtle. If you define the class as:
class Functor f => Printable f where
exprDoc :: f t -> Doc
you can't make recursive calls to sub-expressions. There is, after
all, no reason to believe that "t" is Printable. The following choice
of class is better:
class Functor f => Printable f where
exprDoc :: Printable g => f (Expr g) -> Doc
Now when you define the instance for And, you can safely make
recursive calls to the list of subchildren.
To define the function you want, just add a wrapper to exprDoc:
ppExpr : Printable f => Expr f -> Doc
ppExpr (In t) = exprDoc t
All the best,
Wouter
PS - You may want to add:
infixr 6 :+:
to you code. It'll save you a lot of parentheses!
This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: WouterTest.hs
Type: application/octet-stream
Size: 2694 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080604/9b3a1d9c/WouterTest.obj
-------------- next part --------------
More information about the Haskell-Cafe
mailing list