Could someone please explain ? : type 'a list = 'a :: 'a list | [] The article says "::" is a Data Constructor. I can make sense of type 'a = Left of 'a | Right of 'a where Right and Left are the Data constructors but I don't see the link with the part I don't understand.
type 'a list = [] | (::) of 'a * 'a list
When you write a list like: [x; y; z]
This is syntactic sugar for: x::y::z::[]
Which is syntactic sugar for: (::) (x, (::) (y, (::) (z, [])))
One can imagine using more ordinary constructor names instead: type 'a list = Nil | Cons of 'a * 'a list
And then the above would be: Cons (x, Cons (y, Cons (z, Nil)))
In OCaml, data constructor names mar be either a capital letter followed by set or more capital/lower letters/underscores/apostrophes/digits, or one of the following: []
()
true
false
(::)
Type directed constructor disambiguating means you can do funky things like: type 'a nonempty = (::) of 'a * 'a list
And write such a value just like you would a normal list.