Tuple vs multiple params in F# functions

In my mind, the F# code was almost braceless. I enjoyed reading it because it felt so natural.
Recently, I wrote a bit of F# code. And guess what? There were way too many braces for my taste.
Take a look at this code:

let extractNumbers (numbers: Input, delimiterType: DelimiterType)
let numbers = extractNumbers (input, delimiterType)

Braces all over the place! How did it happen? Was my initial feeling wrong?

Not at all. I've used it wrong. I didn't know how to declare a function with multiple params. Instead, I've defined a tuple as an input.
An improved version could look like this:

let extractNumbers (numbers: Input) (delimiterType: DelimiterType)
let numbers = extractNumbers input delimiterType

Can you spot the difference?
I've changed the definition of the function. Instead of a tuple, now it takes two parameters. I've only skipped coma between the params. And now I feel much better about this code.

Comments (2)

Marek Całus's photo

When I was starting learning F#, it was hard for me to read code without braces. I was very much accustomed to searching for braces to find where are the function names and where are the arguments. When I see x(y, z) I immediately know that x is a function and y and z are the arguments it is called with. When I see x y z It's hard for me to infer anything about the code.

There is some "golden point" between having too much and too less "punctuation symbols" in the code and it mostly depends on what the reader is accustomed to. This, sadly, slows down advancements in programming languages because people won't want to learn languages that are fundamentally different from what they know already.

Kuba Ciechowski's photo

I think that less is better. The less transformations I have to do when translating language we use with BAs, PMs or other stakeholders the more clear the code is.

After writing a lot of boilerplate code it's starting to become more and more annoying. F# succinctness is really refreshing for me.