3 ms·
That last part is trivial: Just put those generic function in a functor, that take a Monad module as a parameter. Assuming I got the functor syntax right (unli
by loup-vaillant 16y ago
That last part is trivial: Just put those generic function in a functor, that take a Monad module as a parameter. Assuming I got the functor syntax right (unlikely), it should look something like:
functor MonadUtils MONAD = struct
sequence : 'a MONAD.monad list -> 'a list MONAD.monad
(* and so on *)
end
- rntz 16y agoClose, but no cigar. functor MonadUtils (M : MONAD) = struct (* type annotations not strictly necessary *) fun sequence (ms : 'a M.monad list) : 'a list M.monad = let fun mcons (elt, rest) = M.bnd elt (fn e => M.bnd rest (fn r => M.ret (e::r))) in foldr mcons (M.ret []) ms end end