[Haskell-cafe] foild function for expressions

Brent Yorgey byorgey at gmail.com
Mon Dec 3 18:41:08 EST 2007


>
> foldExp :: AlgExp a -> Exp -> a
> foldExp alg (LitI i) = litI alg i
> foldExp alg (LitB i) = litB alg i
> foldExp alg (add exp1 exp2) = ¿¿¿???
> foldExp alg (and exp1 exp2) = ¿¿¿???
> foldExp alg (ifte exp1 exp2 exp3) = ¿¿¿???
>

One comment: it looks like (add exp1 exp2), (and exp1 exp2) and so on above
are not correct.  The second argument of foldExp is a value of type Exp, so
you are pattern-matching on the constructors of Exp, and constructors are
always uppercase.  Perhaps Exp has constructors named Add, And, and so on?
Then you would want to do something like

foldExp alg (Add exp1 exp2) = ???

and so on.  For the ??? part, you want to pull out an appropriate function
from your alg record and apply it to exp1 and exp2.

-Brent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20071203/736795c5/attachment.htm


More information about the Haskell-Cafe mailing list