I am working on a function that can count the number of statements used in an expression. My code is as follows:
data Expr = Lit Int | Expr :+: Expr | Expr :-: Expr size :: Expr -> Int size (Lit n) = 0 size (e1 :+: e2) = 1 + (size e1) + (size e2) size (e1 :-: e2) = 1 + (size e1) + (size e2)
But when I try to execute this code using Hugs98, I get the following error:
Main> size 2+3 ERROR - Cannot infer instance *** Instance : Num Expr *** Expression : size 2 + 3
Can someone tell me what I'm doing wrong? I myself am really not myself.
source share