3 ms·
A list is either the empty list [] or Two pieces of data (with the constructor ::) with 1 being the head of the list (type 'a) and one being the tail of the li
by maweki 4y ago
A list is either the empty list [] or
Two pieces of data (with the constructor ::) with 1 being the head of the list (type 'a) and one being the tail of the list (type 'a list, a recursive definition).
:: is an allowed identifier in oCaml. If that is not allowed, the typical names are Cons for :: and Nil for []
- cassepipe 4y agoThanks. I had not understood it could be recursive. Do you know Cons' meaning ? Also why does :: act as a separator... ? Is that something you ca do with any Data constructor, I mean can I write type 'a = 'a Cons of 'a | Nil of 'a ?
- willmorrison 4y agoHere is the Wikipedia page: https://en.m.wikipedia.org/wiki/Cons https://en.m.wikipedia.org/wiki/Cons
- gpderetta 4y agoCons comes from Lisp: https://en.wikipedia.org/wiki/Cons https://en.wikipedia.org/wiki/Cons . In practice a cons cell is a list node represented as a pair of pointers, one pointing to the contained element, the other to the next node (or null, or another element for degenerate lists).
- maweki 4y agoYou would write something like List a = Cons a (List a) | Nil As :: doesn't start with a letter, it's infix by default. But basically a binary constructor. If you want to create the List [1,2,3] in the prefix notation you might be used to: ::(1,::(2,::(3,[])))