I am getting a matching error:
Expression : parseExpr (append p e) es
Term : parseExpr
Type : Expr -> String
Does not match : a -> b -> c
when I try executing this code in the marked line:
data Expr = Atom String | Var String | Pred String [Expr] | Expr String
append :: String -> String -> String
append a b = a++b
parseExpr :: Expr -> String
parseExpr (Atom a) = a
parseExpr (Var x) = x
parseExpr (Pred p (e:es)) = parseExpr (append p e) es -- ERROR HERE
Although e is always going to be a String from the Expr object definition that I stated above. Is there a way to state this?
Perhaps your confusion is here:
This does not mean that every
Expr
can be converted to a string. It just means that there is a function calledExpr
which takes aString
and returns anExpr
(the type).The obvious way to define
parseExpr
for thePred
case is to callparseExpr
on the elements of theExpr
list, e.g.:Perhaps you want
s = intercalate " " strs
to join together the strings with spaces? A concrete example would be helpful.