librarylib/Maybe.xtl
Maybe: a value that may be missing, and the monad that chains computations which can fail (a standard library, built into xetal). Import it with an alias of your choice: "m:" u_se< "Maybe".
A maybe is Church-encoded: it is a function of two arguments, what to give when it is empty and what to do with its value. n_othing gives the first; j_ust x applies the second to x.
Like '+ r_/ A, the function comes first, as a quoted operand, so a chain reads right to left: 'g b_ind 'f b_ind m is f, then g.
Making a maybe
ˡn̲othing : a -> b -> a
ˡn̲othing ← { n j → n }
Using a maybe
ˡm̲aybe : a -> b -> (b -> a -> c) -> c
d 'f m_aybe m: f applied to m's value, or d when m is empty.
ˡm̲aybe ← { f̲ d m̲ → d m̲ 'f̲ }
ˡo̲r : a -> (a -> (b -> b) -> c) -> c
d o_r m: m's value, or d when m is empty.
ˡo̲r ← { d m̲ → d m̲ '{ x → x } }