views:

139

answers:

2

Can someone describe this F# expression to me?

val augment: GameGrid -> points -> unit

What does the val keyword mean?

Is it true that usually type -> type indicates a function that returns the specified type? So does type -> type -> type indicate a function that returns a function that returns the specified type?

+4  A: 

(The 'val' bit is not an expression; offhand I think it can appear in three different contexts:

  • the output of FSI (F# interactive REPL), describing the inferred type of a binding
  • in a signature (.fsi) file, describing the type of a let-bound module value
  • in a struct/class definition ('explicit' syntax), to define an instance variable

and none of those are technically expression contexts.)

As for the type, indeed

A1 -> A2 -> R

means a function that takes an A1, and returns a function that takes an A2 and returns an R. The arguments are curried, and it may do you well to read e.g.

F# function types: fun with tuples and currying

which describes currying and partial application in more detail.

Brian
This came from an FSI file.
Josh G
+3  A: 

How did you get this output? In FSI?

Val just indiciates a definition of a value.

E.g. if you wrote the following in C#

private void Foo(int i);

you would write this in F#

val Foo : int -> unit

Concerning type -> type -> type: This is a function with two parameters (type) returning `type´

E.g.

let plus a b = a + b

has got signature int -> int -> int.

Your idea with a function that returns a function is actually correct. This is a very interesting technique in many functional languages called currying

Dario
Yes, it came from an FSI file.
Josh G