X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?a=blobdiff_plain;f=code%2Fmonads.ml;h=e48fd8d0a0b3a745c1b08ab15c36e428f708457a;hb=73b2ed9e0827afa8bd3e993592c72d98b81afe86;hp=e1865a4a29f5dc109ed9f7bbeb05c25d45bc1931;hpb=4e590cb7725aa4ba86b06491ff2ec9338bc8e347;p=lambda.git diff --git a/code/monads.ml b/code/monads.ml index e1865a4a..e48fd8d0 100644 --- a/code/monads.ml +++ b/code/monads.ml @@ -51,7 +51,8 @@ * - http://www.grabmueller.de/martin/www/pub/Transformers.pdf * - http://en.wikibooks.org/wiki/Haskell/Monad_transformers * - * Licensing: MIT (if that's compatible with the ghc sources). + * Licensing: MIT (if that's compatible with the ghc sources this is partly + * derived from) *) exception Undefined @@ -73,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 @@ -1013,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 @@ -1094,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);; @@ -1104,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))));; @@ -1174,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