From d663eae3baea394ba9d75c24fc05ebb091b87c17 Mon Sep 17 00:00:00 2001 From: Jim Pryor Date: Sun, 12 Dec 2010 16:19:56 -0500 Subject: [PATCH] Leaf_monad -> Tree_monad Signed-off-by: Jim Pryor --- code/monads.ml | 12 ++++++------ monad_library.mdwn | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/code/monads.ml b/code/monads.ml index 54a32483..e48fd8d0 100644 --- a/code/monads.ml +++ b/code/monads.ml @@ -74,7 +74,7 @@ module Util = struct in loop len [] (* Dirty hack to be a default polymorphic zero. * To implement this cleanly, monads without a natural zero - * should always wrap themselves in an option layer (see Leaf_monad). *) + * should always wrap themselves in an option layer (see Tree_monad). *) let undef = Obj.magic (fun () -> raise Undefined) end @@ -1014,14 +1014,14 @@ end *) -module Leaf_monad : sig +module Tree_monad : sig (* We implement the type as `'a tree option` because it has a natural`plus`, * and the rest of the library expects that `plus` and `zero` will come together. *) type 'a tree = Leaf of 'a | Node of ('a tree * 'a tree) type ('x,'a) result = 'a tree option type ('x,'a) result_exn = 'a tree include Monad.S with type ('x,'a) result := ('x,'a) result and type ('x,'a) result_exn := ('x,'a) result_exn - (* LeafT transformer *) + (* TreeT transformer *) module T : functor (Wrapped : Monad.S) -> sig type ('x,'a) result = ('x,'a tree option) Wrapped.result type ('x,'a) result_exn = ('x,'a tree) Wrapped.result_exn @@ -1095,7 +1095,7 @@ end module L = List_monad;; module R = Reader_monad(struct type env = int -> int end);; module S = State_monad(struct type store = int end);; -module T = Leaf_monad;; +module T = Tree_monad;; module LR = L.T(R);; module LS = L.T(S);; module TL = T.T(L);; @@ -1105,7 +1105,7 @@ module C = Continuation_monad module TC = T.T(C);; -print_endline "=== test Leaf(...).distribute ==================";; +print_endline "=== test TreeT(...).distribute ==================";; let t1 = Some (T.Node (T.Node (T.Leaf 2, T.Leaf 3), T.Node (T.Leaf 5, T.Node (T.Leaf 7, T.Leaf 11))));; @@ -1175,7 +1175,7 @@ LS.run (LS.distribute (fun i -> if i = -1 then S.get else if i < 0 then S.(puts - : S.store list * S.store = ([10; 0; 0; 1; 20], 1) *) -print_endline "=== test Leaf(Continuation).distribute ==================";; +print_endline "=== test TreeT(Continuation).distribute ==================";; let id : 'z. 'z -> 'z = fun x -> x diff --git a/monad_library.mdwn b/monad_library.mdwn index 36b6962d..6c6a7a6f 100644 --- a/monad_library.mdwn +++ b/monad_library.mdwn @@ -89,7 +89,7 @@ Some comments on the design of this library. * `Writer_monad` (has to be parameterized on the type of the written data; use `Writer1` as a simple predefined case) * `Error_monad`, with `throw err` and `catch u handler_function` operations (this has to be parameterized on the type of `err`; use `Failure` as a simple predefined case, where `type err = string`) * `IO_monad` (you don't need this in OCaml, but it works analagously to the `IO` monad in Haskell, so it's handy for working with Haskell-written algorithms in OCaml) - * `Leaf_monad` (leaf-labeled, binary trees) + * `Tree_monad` (leaf-labeled, binary trees) * and of course, `Continuation_monad`, with `callcc`, `reset`, `shift` and `abort` operations. * All of these monads come with [[monad transformers]] too. To get a State monad wrapped around a Maybe monad, do this: -- 2.11.0