You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 5612 Reporter:@gasche Assigned to:@damiendoligez Status: closed (set by @xavierleroy on 2015-12-11T18:24:00Z) Resolution: fixed Priority: low Severity: text Target version: 4.01.0+dev Fixed in version: 4.01.0+dev Category: documentation Tags: junior_job Monitored by:@hcarty
Bug description
A beginners_list discussion revealed that some beginners are confused by the spacing style used in the introduction, that plays a dubious ambiguity between OCaml parenthesing rules and the more familiar f(x) notation. Terms like fib(n-2) or square(cos pi) are a potential recipe for disaster once the beginner uses currified functions.
In my experience, such parenthesing and escaping mistakes are actually the number one problem among early OCaml beginners. This section of the manual should be updated to avoid that style.
The text was updated successfully, but these errors were encountered:
Do I understand correctly that you are suggesting we add a space to turn "f(x)" into "f (x)" ? Will that be enough to help the beginners ? If so, I'm all in favor of making the change.
There is also one instance of "f(g(x))", which should obviously replaced by "f (g x)".
Can't we go the whole way and just use "f x" and "f (x + 1)" and "f (g x)" (i.e. miss out all unnecessary parentheses in function applications)?
Beginners, especially those from another language, often think of (x) as a 1-tuple, which contributes to their conviction that f (x, y, z) is a three-argument function rather than a function with a single argument which is a tuple. I think this harms their understanding when they move on to currying.
(Students I teach for Standard ML also universally think unit is the 0-tuple the first time they see it, but that's mostly harmless).
The notation I want to avoid is foo(bar), in particular f(x) (the case where both foo and bar are variables) which is exactly the math notation -- it's best to show as early as possible as OCaml uses a different notation. So we must never have parentheses just after the function expression, and adding a space is one way to avoid having that.
I'd say Damien's proposal to just add spaces is "sufficient". John's suggestion to always use the minimal number of parentheses is not strictly necessary but would be, I think, a good guideline to follow (for expressions built up of function applications at least).
I'm sorry I wasn't clear. What I wanted to propose is exactly John's suggestion, but there are very few actual occurrences of f(x) in the manual, most of these are f(expr) where expr is not a single variable.
My question was whether we also want to add a space in f(expr), and the answer is yes.
Done. I've also added spaces when infix operators are used as prefix (as in List.map (( + ) 1) l).
I have not changed the spacing for constructors because unlike functions they have arity and I think it's good to show that they are not quite like functions. For similar reasons, I haven't touched functor applications (where parentheses are mandatory).
Original bug ID: 5612
Reporter: @gasche
Assigned to: @damiendoligez
Status: closed (set by @xavierleroy on 2015-12-11T18:24:00Z)
Resolution: fixed
Priority: low
Severity: text
Target version: 4.01.0+dev
Fixed in version: 4.01.0+dev
Category: documentation
Tags: junior_job
Monitored by: @hcarty
Bug description
A beginners_list discussion revealed that some beginners are confused by the spacing style used in the introduction, that plays a dubious ambiguity between OCaml parenthesing rules and the more familiar f(x) notation. Terms like fib(n-2) or square(cos pi) are a potential recipe for disaster once the beginner uses currified functions.
In my experience, such parenthesing and escaping mistakes are actually the number one problem among early OCaml beginners. This section of the manual should be updated to avoid that style.
The text was updated successfully, but these errors were encountered: