ml - Missing Option.default in OCaml 4.01.0 -
i'd use string.set.choose some_set
pick string set.
this method returns stringoption, want use method return value of second, hence i'd cast stringoption string.
i know according ocaml docs (link here) option.default
supposed reason it's missing (although option
rest of methods exists).
is there way workaround or let next method accept stringoption?
thanks,
first, not ocaml docs :-) it's add-on library. particular repository obsolete (like else on sourceforge), , option module has been incorporated ocaml batteries included batoption module. batteries add-on library, 1 of used ones.
you can write own function extract string string option, long decide want when value none
. in case, there's no string of course.
one possibility raise exception in case. if you're positive there's string, exception never happen. if happen, know have problem. so, write function this:
let string_of_string_option = match | none -> failwith "string_of_string_option, no string" | str -> str
(this function works list.hd
; i.e., it's partial function raises exception when input not valid.)
you can write own version of default
; it's extremely simple function:
let my_default dflt vo = match vo | none -> dflt | v -> v
a way current ocaml docs go through ocaml.org.
another popular add-on library jane street core, described here. has function named option.value
similar default
function looking for. (in fact, name seems little better me.)
Comments
Post a Comment