Sunday, June 12, 2011

F# Discriminated Union as Option Type



type Options<'a> =
| Some of 'a
| None

let op1 = Some(10.0)
let op2 = None
let op3 = Options.Some("adf")

let ShowOption x =
match x with
| None ->printfn "%A" "Nothing"
| Some t ->printfn "%A" t

ShowOption op1
ShowOption op2
ShowOption op3

No comments: