12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061openBaseincludeStdlib.Optiontype'at='aoptionletis_None:'at->bool=funo->matchowithNone->true|Some_->falseletget:'a->'aoption->'a=fundo->matchowithNone->d|Somee->eletmap_default:('a->'b)->'b->'aoption->'b=funfdo->matchowithNone->d|Somee->feletfold:('a->'b->'a)->'a->'boption->'a=funfao->matchowithNone->a|Someb->fabletcmp:'acmp->'aoptioncmp=funcmp_eltoo'->matcho,o'with|None,None->0|None,Some_->-1|Some_,None->1|Somex,Somex'->cmp_eltxx'leteq:'aeq->'aoptioneq=funeq_elto1o2->matcho1,o2with|None,None->true|Somee1,Somee2->eq_elte1e2|_->falseletpp:'app->'aoptionpp=funeltppfo->matchowithNone->()|Somee->eltppfemoduleMonad=structlet(let*)=Stdlib.Option.bind(** Monadic [let*] allows to replace
{[ Option.bind e (fun x => ...) ]}
or
{[
match e with
| None -> None
| Some x -> ...
]}
with
{[
let* x = e in
...
]} *)letreturnx=SomexendmoduleApplicative=structletpurex=Some xlet(<*>):('a->'b)option->'aoption->'boption=funox->matchowith|Somef->mapfx|None->Noneend