Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 750
Andry Avatar asked Dec 13 '10 13:12

Andry


People also ask

What are parameters in a function?

A parameter is a named variable passed into a function. Parameter variables are used to import arguments into functions. For example: function example(parameter) { console.

What is a parameter in a function example?

The parameters, in a function call, are the function's arguments. JavaScript arguments are passed by value: The function only gets to know the values, not the argument's locations. If a function changes an argument's value, it does not change the parameter's original value.

How do you define a variable in a function?

A variable represents a concept or an item whose magnitude can be represented by a number, i.e. measured quantitatively. Variables are called variables because they vary, i.e. they can have a variety of values. Thus a variable can be considered as a quantity which assumes a variety of values in a particular problem.

How do you define parameters in Python?

The terms parameter and argument can be used for the same thing: information that are passed into a function. From a function's perspective: A parameter is the variable listed inside the parentheses in the function definition. An argument is the value that is sent to the function when it is called.


1 Answers

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

like image 72
Tim Robinson Avatar answered Sep 30 '22 16:09

Tim Robinson