question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Different indentation level changes behaviour of the code

See original GitHub issue
let 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:closed
  • Created 7 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
radekmcommented, Apr 2, 2016

IMO it seems correct - see the specification 15.1.9 Exceptions to the Offside Rules - the first exception:

An infix token may be offside by the size of the token plus one.

Here is a similar example:

let (||>) = (|>)

let () =
    let x =
        match "" with
        | "" -> 1
        | _ ->
            4
        |> (+) 9
    printfn "%A" x

The code prints 10 because the exception doesn’t apply (the expression in the second branch of match is 4).

But if you replace |> by ||> or decrease the indentation of the line with 4 by one space the result will change to 1 because the exception to the offside rule will apply (the expression in the second branch of match will be 4 |> (+) 9).

0reactions
dsymecommented, Apr 5, 2016

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found