This is not a homework question, rather an exam study guide question. What is the difference between pattern matching in Prolog Vs Haskell?
I\'ve done some research and
Here is an example I find interesting in Prolog to support @chac (+1 btw) mention about how Prolog's unification "builds" terms that we ran into in the prolog tag yesterday:
swapPairs([], []).
swapPairs([X], [X]).
swapPairs([X, Y|T], [Y, X|R]) :- swapPairs(T, R).
This predicate has almost no "body". It only uses unification of its arguments in its head and recursion.
As pointed out by both @chac and @LeleDumbo, that's because Prolog's unification is "both-way".
Here is what A gentle Introduction to Haskell says about it:
Pattern matching in Haskell is different from that found in logic programming languages such as Prolog; in particular, it can be viewed as "one-way" matching, whereas Prolog allows "two-way" matching (via unification), along with implicit backtracking in its evaluation mechanism.