F# Functions vs. Values

The right way to look at this is that F# has no such thing as parameter-less functions. All functions have to take a parameter, but sometimes you don’t care what it is, so you use () (the singleton value of type unit). You could also make a function like this:

let printRandom unused = 
  x = MyApplication.getRandom()
  printfn "%d" x
  x

or this:

let printRandom _ = 
  x = MyApplication.getRandom()
  printfn "%d" x
  x

But () is the default way to express that you don’t use the parameter. It expresses that fact to the caller, because the type is unit -> int not 'a -> int; as well as to the reader, because the call site is printRandom () not printRandom "unused".

Currying and composition do in fact rely on the fact that all functions take one parameter and return one value.

The most common way to write calls with unit, by the way, is with a space, especially in the non .NET relatives of F# like Caml, SML and Haskell. That’s because () is a singleton value, not a syntactic thing like it is in C#.

Leave a Comment