r/fsharp • u/burtgummer45 • Jun 04 '26
question formatting question from a newb
Just starting out with F# and I'm enjoying all the whitespace but to my newbie eyes I think I've spotted an inconsistency in how fantomas formats. Maybe somebody can explain it.
// function that takes param of int*int
let myFun (x, y) = x + y
let r = myFun (1, 2) // <--- fantomas formats with space before tuple, makes sense
let dict = new Dictionary<int, int>()
// dict.Add takes a single tuple of int*int, just like the above function
dict.Add (1, 2) // <--- looks right, takes a tuple
// fantomas doesn't like the clarity and smushes it, why?
dict.Add(1, 1) // <--- yuck, now it looks like a function call with two arguments in another language
9
Upvotes
12
u/bokeh-man Jun 04 '26
I guess this is how F# lives between the two worlds: FP and OOP. `myFun` is a function and F# uses ML parameter format for that. `dict.Add()` is a C# method and methods always takes a tuple of parameters. F# (or Fantomas) follows C# method calling syntax for that. When I see `()` after a name without a space, and the name starts with a capital letter, I know instantly that this is a method call.
7
u/icalvo Jun 04 '26
My guess, if this is not a bug, is that Fantomas wants the C# interoperability calls to have the C# standard style as a hint that they are kind of different (because they are not like F# type members in that they always take a single tuple parameter)
6
u/TarMil Jun 04 '26
One thing to note is that using a space breaks chained method calls.
This fails to compile, because F# sees this as calling the method Bar on the tuple (1, 2), rather than on the result of the call to the method Foo.
2
u/phillipcarter2 Jun 04 '26
See here for details: https://learn.microsoft.com/en-us/dotnet/fsharp/style-guide/formatting
7
u/binarycow Jun 04 '26
Technically, no.
dict.Addis a method that accepts two parameters.F# just makes it look like it takes a tuple.
1
u/AppropriateTeach169 Jun 04 '26
How can this be disabled. I think consistency is what matters most and in F#, I feel like the additional space is clearer and more explicit about what's going on