F# - Returning Nullable objects from a function

Post date: Dec 29, 2011 11:09:45 PM

"Some" is basically boxing the value while "None" is to be considered as null. In this example we box and return a int*int tuple if everything goes OK.

let GetNum x = try Some(100 / x, 500 / x) with | :? System.DivideByZeroException | :? System.OverflowException -> Nonelet f a = match a with | Some(tupl) -> printfn "%A" tupl | None -> printfn "An error must have occured since there is no value" f (GetNum 0) f (GetNum 20)