X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=hints%2Fassignment_10_hint_4.mdwn;h=ee6f8bc62e29f511588f6eab440379edf2b5aaa1;hp=bb5a79975840a098b6f584d4634c595e6dbd82bf;hb=8cf1fe240800a66d644f907fad8d618b014efd7d;hpb=e8c44d33c131b04cf7b61f083a4a4f59d2484d84 diff --git a/hints/assignment_10_hint_4.mdwn b/hints/assignment_10_hint_4.mdwn index bb5a7997..ee6f8bc6 100644 --- a/hints/assignment_10_hint_4.mdwn +++ b/hints/assignment_10_hint_4.mdwn @@ -49,12 +49,13 @@ I said earlier, the encapsulation enforced by that library may make it somewhat module TC = T.T(C);; module TS = T.T(S);; module TR = T.T(R);; + let tree = Some (T.Node(T.Leaf '1', T.Node(T.Leaf '2', T.Node(T.Leaf '3', T.Leaf '1'))));; # let v0 = TC.(run_exn (distribute (fun a -> C.(shift (fun k -> k a >>= fun v -> unit (1+v))) ) tree)) (fun a -> 0);; - - : int = 5 + - : int = 4 # let v1 = TC.(run_exn (distribute (fun a -> @@ -69,8 +70,10 @@ I said earlier, the encapsulation enforced by that library may make it somewhat v1 '2';; ~~> 1 *) + # let annotater : char -> ('x, char) S.m = + fun a -> S.(puts (fun s -> (update_env s a)) >> unit a);; # let v2 = TS.(run (distribute annotater tree)) (fun a -> 0);; - # let (tree',env) = v2 in TR.(run (distribute (fun a -> a) tree')) env;; + # let (t, env) = v2 in TR.(run (distribute (fun a -> R.asks (fun e -> e a)) t)) env;; (* returns tree with leafs replaced with their numbers of occurrences *)