First, you can always fix the equality between template variables using the when clause in OCaml, for example:
let rec destutter = function | [] -> [] | [hd] -> [hd] | hd :: hd' :: tl when hd = hd' -> destutter (hd :: tl) | hd :: hd' :: tl -> hd :: destutter (hd' :: tl)
There is a compromise here. Although Erlang is more expressive, OCaml pattern matching is simpler (meaning a simpler language definition, compiler, etc.), and you can still do what you need (by writing more code).
Note that while you can rewrite a non-linear pattern as a linear pattern with the when clause, this is not a major issue. More critically, pattern matching should then have the notion of equality for arbitrary types in order to support non-linear patterns. This is not a problem in Erlang, but OCaml not only has a built-in = vs == (structural equality versus identity), but for any given type it may not be the equality you need (for example, thought strings and case sensitivity). Then, as a result, exhaustiveness or overlap testing becomes non-trivial. In the end, it is doubtful whether it is worth providing a special case for one particular type of equality, given how many useful relationships between parts of the template can be. (I note that non-strict languages have additional problems.)
In contrast, Prolog pattern matching is based on unification and is strictly more powerful than Erlang or OCaml (but also harder to implement).
source share