
On Dec 3, 2007 12:18 PM, Carlo Vivari
Hi! I'm a begginer in haskell and I have a problem with an exercise, I expect someone could help me:
In one hand I have a declaration of an algebra data, like this:
data AlgExp a = AlgExp { litI :: Int -> a, litB :: Bool -> a, add :: a -> a -> a, and :: a -> a -> a, ifte :: a -> a -> a -> a}
(being ifte an 'ifthenelse' expresion...)
What I want to do is to write a fold function for expressions, something like this:
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) = ¿¿¿???
You'll want something like this:
foldExp alg (Add e1 e2) = add alg (foldExp alg e1) (foldExp alg e2)
--
Dave Menendez