Commits

jhwoodyatt  committed d9724dd

Improve the continuation monad and state-continuation monad modules.

  • Participants
  • Parent commits 485e192

Comments (0)

Files changed (5)

 + Improvements to [Cf_cmonad] and [Cf_scmonad].
 
 --- [Cf_scmonad]
-    Added the [transform] and [eval] functions.  Cleaned up the documentation.
+    Added the [bridge] and [eval] functions.
+    Cleaned up the documentation.
 
 --- [Cf_cmonad]
+    Added [bridge] function.
     Cleanup the documentation.
 
 ===== Version 0.10 =====

File cf/cf_cmonad.ml

 let init y _ = y
 let cont f g = f (g ())
 let eval m x = m (fun () -> x)
+let bridge x b m _ = b (m (fun () -> x))
 
 (*--- End of File [ cf_cmonad.ml ] ---*)

File cf/cf_cmonad.mli

 *)
 val eval: ('x, unit) t -> 'x -> 'x
 
+(** Use [bridge x f m] as a shortcut for [init (f (eval m x))]. *)
+val bridge: 'x -> ('x -> 'y) -> ('x, unit) t -> ('y, unit) t
+
 (*--- End of File [ cf_cmonad.mli ] ---*)

File cf/cf_scmonad.ml

 let down m s f = m (fun () -> f) s
 let lift = Op.( >>= )
 let eval m s x = m (fun () _ -> x) s
+let bridge x b m _ s = b (m (fun () _ -> x) s)
 
 (*--- End of File [ cf_scmonad.ml ] ---*)

File cf/cf_scmonad.mli

 *)
 val eval: ('s, 'x, unit) t -> 's -> 'x -> 'x
 
+(** Use [bridge x f m] to lower the state-continuation monad [m], then bridge
+	with the initial context [x] and a map function [f], and finally lift the
+	result to another state-contination monad, one that evaluates [m] using the
+	state bridged from the result monad.
+*)
+val bridge: 'x -> ('x -> 'y) -> ('s, 'x, unit) t -> ('s, 'y, unit) t
+
 (*--- End of File [ cf_scmonad.mli ] ---*)