0005612: Rationalize spacing and parenteses use in the tutorial part of the manual

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.

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