News for hackers. Stuff that matters.
Re:What I wish I knew when learning OCaml (2018) by maweki on Tuesday May 03, 2022 @07:38AM (#31247077)
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 []

Re:What I wish I knew when learning OCaml (2018) by cassepipe on Tuesday May 03, 2022 @07:59AM (#31247241)
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 ?

Re:What I wish I knew when learning OCaml (2018) by gpderetta on Tuesday May 03, 2022 @08:05AM (#31247282)
Cons comes from Lisp: 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).
Re:What I wish I knew when learning OCaml (2018) by maweki on Tuesday May 03, 2022 @09:20AM (#31247924)
You 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,[])))

Re:What I wish I knew when learning OCaml (2018) by willmorrison on Tuesday May 03, 2022 @08:02AM (#31247274)
Here is the Wikipedia page: https://en.m.wikipedia.org/wiki/Cons