Hi, I am doing some simple exercises about recursive algebraic types and this
particular exercise asks to define a function which counts the number of
operators in an expression.  I defined the function below, but i am not sure
if on the second line changing from "evalLength (Lit n) = n" to "(Lit n) =
0" is the right solution.  although the function produces correct result.

data Expr = Lit Int | Add Expr Expr |
                Sub Expr Expr
                deriving (Eq, Show)

evalLength :: Expr -> Int
evalLength (Lit n) = 0
evalLength (Add e1 e2) = 1 + (evalLength e1) + (evalLength e2)
evalLength (Sub e1 e2) = 1 + (evalLength e1) - (evalLength e2)


Thank you 
-- 
View this message in context: 
http://www.nabble.com/Primitive-Recursive-Algebraic-Types-tf4207521.html#a11969026
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to