>missed it in languages like Clojure
I'm not sure about Haskell and Erlang/Elixir since I haven't used them much, but aren't multimethods the Clojure solution for this?
Not really, what Haskell / Erlang offer is that you can do pattern matching in the function signature.
So you can, say, have a definition for when the value of n is 0, n is 1, etc.
This is a nice example in Haskell:
compress :: Eq a => [a] -> [a] compress [] = [] compress [x] = [x] compress (x:ys@(y:_)) | x == y = compress ys | otherwise = x : compress ys
Not really, what Haskell / Erlang offer is that you can do pattern matching in the function signature.
So you can, say, have a definition for when the value of n is 0, n is 1, etc.
This is a nice example in Haskell:
Basically it enables you to use recursion more elegantly because the pattern matching is folded into the function signature.