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:
Some
which holds a value of some type.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
2009-01-16 12:56:15
+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
2009-01-16 13:48:03