[Haskell-cafe] foild function for expressions
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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe