-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Closed
Labels
Description
I think we ought to mention that whitespace is sometimes necessary and since this is a guideline, we should enumerate the cases to create consistency.
I suggest we add something like this (text to be defined):
- Around infix operators, whitespace should be used:
1 + 3, not1+3. This avoids problems likex -1which is a different expression entirely tox - 1. - Mention that whitespace following a function identifier can be necessary.
myFunction()is different frommyFunction (). The advice should be that in general, when it is a .NET member function, no space is used after the identifier. When it is a curried function, or a standard F# function, a space is required. While there are cases where both syntaxes yield the same result, this is the place to give a guideline, which hopefully avoids common pitfalls encountered by newcomers. - After prefix operators, no space should be used. Good:
x = -1, bad:x = - 1. - In operator definitions, a space should be used. This prevents certain compile errors, and consistency is key here. Good:
( !. ) y = y, bad:(!.) y = y. (i.e., a compile error will happen when an operator starts with a*and you don't use a space). - Around
->there should always be a space. Goodfunction X -> y, bad:function X->y.
... anything else I've missed?
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 8c09996f-24ac-cf39-ef43-d7909cbc2b89
- Version Independent ID: 1efdd523-8552-6421-e149-74f76826ef8f
- Content: F# code formatting guidelines
- Content Source: docs/fsharp/style-guide/formatting.md
- Product: dotnet-fsharp
- GitHub Login: @cartermp
- Microsoft Alias: phcart