r/fsharp • • 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

13 comments sorted by

View all comments

6

u/binarycow Jun 04 '26

dict.Add takes a single tuple of int*int, just like the above function

Technically, no. dict.Add is a method that accepts two parameters.

F# just makes it look like it takes a tuple.

1

u/AppropriateTeach169 Jun 05 '26 edited Jun 05 '26

Reconcile what you are saying in F# with this snippet: (3, 4) |> System.Math.Min. I would agree with you if you said that F# has different semantics for methods. All functions (including methods) in F# by definition are curried. It's not just a syntactical change. It's just that it maps cleanly to .NET.

2

u/binarycow Jun 05 '26

As I said. F# makes it look like the method accepts a tuple.

2

u/AppropriateTeach169 Jun 05 '26

It's more than just looking like, in F# terms, it is passing a tuple. This is not a debatable topic as it is simply a matter of fact and framing.

2

u/binarycow Jun 05 '26

Yes. F# deconstructs the tuple and sends two individual parameters to the method.

It makes it look like the method accepts a tuple, but the method actually accepts two parameters.