Elm allows you to define polymorphic functions.
Parametric polymorphism is when a function can be applied to elements of any type:
f : (a, b) -> (b, a)
f (x, y) = (y, x)
Ad-hoc polymorphism is when a function can be applied to elements of certain types:
g : appendable -> appendable -> appendable -> appendable
g x y z = x ++ y ++ z
h : number -> number -> number
h x y = (x + 2) * y
Variables of type numberand appendableare special because they are a subset of all types of Elm. Listand Stringare appendable, while Floatand Intare the types of numbers.
hasPlus, List, String, Float Int, , , x + y y + x, , ...