Library
Module
Module type
Parameter
Class
Class type
There's also the PResultM
monad which has a return
function that wrapps its input in a Win
constructor, and the bind (>>=)
operator which applies a function to a p_result
value if that value is a Win
value.
Also includes a fail
function that returns an error message, and (=<<)
infix function to handle any Lose
cases.
It's a basic monad but it helped string a few things along easier.
val return : ('b * 'a) -> ('a, 'b) p_result
Takes in a tuple of type ('b * 'a)
and returns it wrapped in a Win
constructor
return (b, a) = Win (b, a)
Bind function, takes in a p_result
and if the result is a Win
, the function is applied to the tuple inside. If the result is a Lose
, the result is just returned without any change.
Win (b, a) >>= fun (a1, a2) ->
(a1 = b) && (a2 = a)
val fail : string -> ('a, 'b) p_result
Fail function that takes in a string and evaluates to Lose
with that string as a fail message
fail a -> Lose a