Well, when you look at that definition of Exp
, you can see there's a whole pile of possible constructors. But in your function, you're only checking for two of them.
So what happens if I call fromExp (Lit l)
? It's undefined, which isn't good. The easiest way to fix this is to add in one more case that covers every other possible constructor:
fromExp :: Exp -> String
fromExp (Var qn) = fromQName qn
fromExp (Paren e1) = "()"
fromExp _ = "Not defined yet"
This way if you call fromExp
with any other constructor, it will return "Not defined yet"
.
In this specific case, the evaluation is:
vars t3
=> vars (InfixApp (Var (UnQual (Ident "x"))) (QVarOp (UnQual (Symbol "+"))) (Paren (InfixApp (Lit (Int 3)) (QVarOp (UnQual (Symbol "+"))) (Lit (Int 2)))))
=> vars (Paren (InfixApp (Lit (Int 3)) (QVarOp (UnQual (Symbol "+"))) (Lit (Int 2)))))
=> vars (InfixApp (Lit (Int 3)) (QVarOp (UnQual (Symbol "+"))) (Lit (Int 2))))
=> fromExp (Lit (Int 3))
and there is no fromExp (Lit l)
definition to evaluate that expression.