Different indentation level changes behaviour of the code
See original GitHub issuelet foo t = "(" + t + ")"
let tttt =
let text =
match Some "" with
| Some t ->
match t with
| "" ->
"a"
| "b" ->
"b"
|> foo
| _ -> "fooo"
text
let tttt' =
let text =
match Some "" with
| Some t ->
match t with
| "" ->
"a"
| "b" ->
"b"
|> foo
| _ -> "fooo"
text
In foo
I use two spaces for indentation, in foo'
four spaces are used.
The resulting expressions are different while I’d had expected those to be the same.
I tried to find something which would explain that in the language specification (which I haven’t thoroughly read) but failed, and the behaviour seems to fail me at “principle of least surprise” so submitting this as an issue to get clarification.
Thanks.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
What 'inconsistent use of tabs and spaces in indentation ...
Python uses white spaces to indicate code blocks; in this sense, it is the odd one out. However, using white spaces for indentation...
Read more >What is indentation in programming, and why is it needed?
Indentation indicates the level of nesting of control constructs such as branches (e.g., if, switch) and loops (e.g., for, while) as well as...
Read more >Code Blocks and Indentation | Flow of Control in Python
In this chapter, Toby Donaldson looks at how to change the order in which statements are executed by using if-statements and loops.
Read more >Indentation
An indentation or indent is a technique that is used to appoint paragraphs or other logical blocks in the code. In Silverfin, there...
Read more >c# - Visual Studio 2015 indentation behavior for files with ...
I want to avoid having to format the whole document and checking those changes in to version control, just to be able to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
IMO it seems correct - see the specification 15.1.9 Exceptions to the Offside Rules - the first exception:
Here is a similar example:
The code prints
10
because the exception doesn’t apply (the expression in the second branch of match is4
).But if you replace
|>
by||>
or decrease the indentation of the line with4
by one space the result will change to1
because the exception to the offside rule will apply (the expression in the second branch of match will be4 |> (+) 9
).@smoothdeveloper We try really, really hard not to add compiler flags that “fork” the language (or even restrict it). It’s possible that adding the warning to FSharpLint or Fantomas or FSharp.Compiler.Service may be the right place.