Re:OCaml at First Glance
by tomp on Monday August 29, 2022 @10:03AM
(#32638381)
No, it’s actually because , (comma) denotes a tuple.
is a list of tuples, of type (int * int) list, equivalent to
[ Parent
| on HN ]
I never understood the motivation for allowing tuples without surrounding parens. There are a few very simple functions that look cuter this way, but it constantly trips me up in more complex situations.
Re:OCaml at First Glance
by a-nikolaev on Monday August 29, 2022 @12:04PM
(#32639829)
No parentheses can be nice for cleaner pattern matching, e.g. something like this:
match a, b with
| 1, 2 -> x
| _ -> yThis phenomenon is actually another example of the phenomenon he mentions. In strict precedence parsing, operators are assigned meaning rather than productions of a grammar (which would could those operators in distinct contexts), so once you've decided a comma indicates a tuple, it's easier to just allow this syntax.
Re:OCaml at First Glance
by goodoldneon on Monday August 29, 2022 @10:10AM
(#32638461)
The "comma makes a tuple" behavior is a big gotcha I've experienced in Python. I wish that behavior didn't exist
Which version of that are you talking about in Python? The biggest related gotcha I've seen in Python is when you have a trailing comma `x = 1,` and accidentally create a tuple.
Re:OCaml at First Glance
by goodoldneon on Monday August 29, 2022 @11:27AM
(#32639427)
Yea that’s the most common gotcha