Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rationalize spacing and parenteses use in the tutorial part of the manual #5612

Closed
vicuna opened this issue May 10, 2012 · 5 comments
Closed

Comments

@vicuna
Copy link

vicuna commented May 10, 2012

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.

@vicuna
Copy link
Author

vicuna commented Aug 19, 2013

Comment author: @damiendoligez

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)".

@vicuna
Copy link
Author

vicuna commented Aug 20, 2013

Comment author: @johnwhitington

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).

@vicuna
Copy link
Author

vicuna commented Aug 20, 2013

Comment author: @gasche

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).

@vicuna
Copy link
Author

vicuna commented Sep 2, 2013

Comment author: @damiendoligez

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.

I'll do the changes when I'm done with the RC.

@vicuna
Copy link
Author

vicuna commented Sep 2, 2013

Comment author: @damiendoligez

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).

Fixed in rev 14053.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants