3 ms·
Thanks. 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 an
by cassepipe 5y ago
Thanks. 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 5y agoHere is the Wikipedia page: https://en.m.wikipedia.org/wiki/Cons https://en.m.wikipedia.org/wiki/Cons
- gpderetta 5y 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 5y 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,[])))