I am trying to implement a function that compares 2 lists to see if they are the same. The syntax looks fine to me:
compare :: String -> String -> Bool
compare [] [] = True -- error here
compare (x,xs) (y,ys) = if x == y
then compare xs ys
else False
but I keep getting this error in the line marked above:
Syntax error in input (unexpected `=')
When I tried replacing '=' with '->', it worked fine but it gave the same error in the following line. So I did the same:
compare :: String -> String -> Bool
compare [] [] -> True
compare (x,xs) (y,ys) -> if x == y -- new error here
then compare xs ys
else False
But I got a different error:
Syntax error in type signature (unexpected keyword "if")
Now I really have no idea what's going on.
Your original first function is right except the fact that you are pattern matching it wrong. It should be like this:
Also as @ThreeFx suggested, do format your code properly. Ultimately it should look like this: