Re:What I wish I knew when learning OCaml (2018)
by dan-robertson on Tuesday May 03, 2022 @12:55PM
(#31250581)
The definition of list is:
When you write a list like:
This is syntactic sugar for:
Which is syntactic sugar for:
One can imagine using more ordinary constructor names instead:
And then the above would be:
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:
Type directed constructor disambiguating means you can do funky things like:
And write such a value just like you would a normal list.
[ Parent
| on HN ]
Re:What I wish I knew when learning OCaml (2018)
by cassepipe on Tuesday May 03, 2022 @02:01PM
(#31251401)
Thanks for the detailed explanation. One more question though, when I write
type 'a = 'a :: list 'a
It is syntactic sugar that allows me to get the * product type for free, right ?
Re:What I wish I knew when learning OCaml (2018)
by yawaramin on Tuesday May 03, 2022 @04:17PM
(#31253022)
That's actually invalid syntax. '::' can't be used infix in a type declaration. And type application is in reverse. So it's not list 'a but 'a list.
Re:What I wish I knew when learning OCaml (2018)
by dan-robertson on Tuesday May 03, 2022 @03:53PM
(#31252752)
I think that is made up syntax from the article but maybe I’m wrong.