F # Expression Semantics
Can anyone describe this F # expression for me?
val augment: GameGrid -> points -> unit
What does the keyword mean val
?
Is it true that a function that returns a specified type usually indicates? So, it points to a function that returns a function that returns the specified type? type -> type
type -> type -> type
a source to share
(the 'val' bit is not an expression, because I believe it can appear in three different contexts:
- FSI (F # interactive REPL) output describing the intended binding type
- in a signature file (.fsi) describing the value type of the associated module
- in a struct / class definition ("explicit" syntax) to define an instance variable
and none of these are technically the context of the expression.)
As for the type, indeed
A1 -> A2 -> R
means a function that takes A1 and returns a function that takes A2 and returns R. The arguments are curried and you might find it helpful to read eg.
F # function types: fun with tuples and currying
which describes currying and partial application in more detail.
a source to share
How did you get this result? FSI?
Val simply indicates the definition of a value.
eg. if you wrote the following in c #
private void Foo(int i);
you have to write this in F #
val Foo : int -> unit
Relatively type -> type -> type
: This is a function with two (type) parameters returning `type '
eg.
let plus a b = a + b
has a signature int -> int -> int
.
Your idea with a function returning a function is indeed correct. This is a very interesting technique in many functional languages ββcalled currying
a source to share