X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=code%2Fmonads.ml;h=b678a92c28a75c78e257e55a9979268477b09e3e;hp=e48fd8d0a0b3a745c1b08ab15c36e428f708457a;hb=6620761d57706f681ccf431c19d6d6fd77fa2942;hpb=b7e79cc4e5a802b16cec8d1832de2bf646a64879;ds=sidebyside diff --git a/code/monads.ml b/code/monads.ml index e48fd8d0..b678a92c 100644 --- a/code/monads.ml +++ b/code/monads.ml @@ -415,13 +415,6 @@ end = struct end end -(* -# LL.(run(plus (unit 1) (unit 2) >>= fun i -> plus (unit i) (unit(10*i)) ));; -- : ('_a, int) LL.result = [[1; 10; 2; 20]] -# LL.(run(plus (unit 1) (unit 2) >>= fun i -> elevate L.(plus (unit i) (unit(10*i)) )));; -- : ('_a, int) LL.result = [[1; 2]; [1; 20]; [10; 2]; [10; 20]] -*) - (* must be parameterized on (struct type err = ... end) *) module Error_monad(Err : sig @@ -516,26 +509,6 @@ module Failure = Error_monad(struct *) end) -(* -# EL.(run( plus (throw "bye") (unit 20) >>= fun i -> unit(i+10)));; -- : int EL.result = [Failure.Error "bye"; Failure.Success 30] -# LE.(run( plus (elevate (Failure.throw "bye")) (unit 20) >>= fun i -> unit(i+10)));; -- : int LE.result = Failure.Error "bye" -# EL.(run_exn( plus (throw "bye") (unit 20) >>= fun i -> unit(i+10)));; -Exception: Failure "bye". -# LE.(run_exn( plus (elevate (Failure.throw "bye")) (unit 20) >>= fun i -> unit(i+10)));; -Exception: Failure "bye". - -# ES.(run( elevate (S.puts succ) >> throw "bye" >> elevate S.get >>= fun i -> unit(i+10) )) 0;; -- : int Failure.error * S.store = (Failure.Error "bye", 1) -# SE.(run( puts succ >> elevate (Failure.throw "bye") >> get >>= fun i -> unit(i+10) )) 0;; -- : (int * S.store) Failure.result = Failure.Error "bye" -# ES.(run_exn( elevate (S.puts succ) >> throw "bye" >> elevate S.get >>= fun i -> unit(i+10) )) 0;; -Exception: Failure "bye". -# SE.(run_exn( puts succ >> elevate (Failure.throw "bye") >> get >>= fun i -> unit(i+10) )) 0;; -Exception: Failure "bye". - *) - (* must be parameterized on (struct type env = ... end) *) module Reader_monad(Env : sig type env end) : sig @@ -667,6 +640,7 @@ end = struct end end + (* State monad with different interface (structured store) *) module Ref_monad(V : sig type value