So, Options. It's a standard Nullable wrapper that goes all the way back to ML.
Usage looks like:
let exists (x : int option) = match x with | Some(x) -> true | None -> false
While matching is nice, sometimes I just need a Some x or y kind of thing. I ended up writing this, which works fine:
// returns d if o is None let dov<'a> (d:'a) (o:'a option) = match o with | Some x->x | None->d // e.g. [ Some 4; None; Some 12] |> List.map (dov 42) val it : int list = [4; 42; 12]
While the default value in front is a little awkward, the currying for things like the above example seems worth it.
Note, ocaml's function, similar to this, is map_default.
The question is, am I missing something? Is there some simple built in way to do this? Or is this somehow considered bad form?