tags:

views:

783

answers:

2
+6  Q: 

F# keyword 'Some'

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

+16  A: 

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()
Mehrdad Afshari
+2  A: 

Can check out Discriminated Unions in F# for more info on DUs in general and the option type (Some, None) in particular. As a previous answer says, Some is just a union-case of the option<'a> type, which is a particularly common/useful example of an algebraic data type.

Brian