I have a small Erlang function that compares if two lists are equal:
myEq([], []) -> true;
myEq([X|Xs], [X|Ys]) -> myEq(Xs, Ys);
myEq(_, _) -> false.
The comparison takes place on line 2, the X
of [X|Xs]
always binds to the first element of the first list, the [X|Ys]
matches only if the first elements of both lists are equal.
If I try this in Haskell I get an error message: "Conflicting definitions for x
".
A possible solution in Haskell would be:
myEq (x:xs) (y:ys) = if x == y then myEq xs ys else False
But I would like to know if it is possible to do this in Haskell using pattern matching?