1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859openBaseincludeStdlib.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
{[
match e1 with
| Some e2 -> Some (f e2)
| None -> None
]}
with
{[
let* x = e1 in
f x
]} *)letreturnx=SomexendmoduleApplicative=structletpurex=Somexlet(<*>):('a->'b)option->'aoption->'boption=funox->matchowith|Somef->mapfx|None->Noneend