X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=monad_transformers.mdwn;h=0e9d928447202797325efadd5188cbb64635c507;hp=57affe5995da3cd4b2cc918b1d4270132825ee9a;hb=51f881475438eba8f8533e5e0a91ee087e72aaaf;hpb=4bab63e9b62e289b7feeae89cea4a1e27a0fe0f1 diff --git a/monad_transformers.mdwn b/monad_transformers.mdwn index 57affe59..0e9d9284 100644 --- a/monad_transformers.mdwn +++ b/monad_transformers.mdwn @@ -135,6 +135,8 @@ Apart from whose interface is outermost, the behavior of a StateT(Maybe) and a M # module SM = S.T(Maybe_monad);; # MS.(run (elevate (S.puts succ) >> zero () >> elevate S.get >>= fun cur -> unit (cur+10) )) 0;; - : int option * S.store = (None, 1) + # MS.(run (elevate (S.puts succ) >> zero () >> elevate (S.put 5) )) 0;; + - : unit option * S.store = (None, 1) Although we have a wrapped `None`, notice that the store (as it was at the point of failure) is still retrievable. @@ -154,7 +156,7 @@ When Maybe is on the inside, on the other hand, a failure means the whole comput Exception: Failure "bye". --> -Here's an example wrapping List around Maybe, and vice versa: +Here's an example wrapping Maybe around List, and vice versa: # module LM = List_monad.T(Maybe_monad);; # module ML = Maybe_monad.T(List_monad);; @@ -186,7 +188,7 @@ This is fun. Notice the difference it makes whether the second `plus` is native # 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]] + - : ('_a, int) LL.result = [[1; 2]; [1; 20]; [10; 2]; [10; 20]]