« Return to Thread: foild function for expressions

Re: foild function for expressions

by David Menendez-2 :: Rate this Message:

Reply to Author | View in Thread



On Dec 3, 2007 12:18 PM, Carlo Vivari <thrakatak@...> wrote:

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 <dave@...>
<http://www.eyrie.org/~zednenem/>
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@...
http://www.haskell.org/mailman/listinfo/haskell-cafe

 « Return to Thread: foild function for expressions