Andry
Andry

Reputation: 16845

Definining parameters in F# functions, is it better using tuples?

A simple question... Is it good practice to define a function accepting more than 1 parameter through tuples?

I explain myself better: I have a function:

let myfunc par1 par2 = ...;;

Is it good to to so?

let myfunc (par1, par2) = ...;;

When I say "is it good" I am saying: is it good practice? is it good to do this ALWAYS as a common practice to pass parameters to a function??

Thank you

Upvotes: 5

Views: 252

Answers (1)

Tim Robinson
Tim Robinson

Reputation: 54724

Normal F# style is to define functions curried, i.e. non-tupled according to your first example.

Currying lets you do this: ("partial application")

let myfunc par1 par2 = ...
let myfuncHello = myfunc "Hello"
myfuncHello "World" // same as: myfunc "Hello" "World"

However, if you expose your code to .NET languages other than F#, stick with tupling, since it's hard to call curried functions except from F#.

Edit: from the brand new F# Snippets site: http://fssnip.net/I

Upvotes: 5

Related Questions