F# keyword 'Some'

Vlad picture Vlad · Jan 16, 2009 · Viewed 8.2k times · Source

F# keyword 'Some' - what does it mean?

Answer

Mehrdad Afshari picture Mehrdad Afshari · Jan 16, 2009

Some is not a keyword. There is an option type however, which is a discriminated union containing two things:

  1. Some which holds a value of some type.
  2. None which represents lack of value.

It's defined as:

type 'a option =
    | None
    | Some of 'a

It acts kind of like a nullable type, where you want to have an object which can hold a value of some type or have no value at all.

let stringRepresentationOfSomeObject (x : 'a option) =
    match x with
    | None -> "NONE!"
    | Some(t) -> t.ToString()