open SMLofNJ.Cont; datatype ('a, 'b) chan = Chan of ('a * ('b, 'a) chan) cont; fun sw x (Chan k) = callcc ( fn k' => throw k (x, Chan k') ); fun rx c = sw () c fun tx x c = #2 (sw x c) fun source d = let val _ = print "source starting\n" val d = tx "hel" d val d = tx "lo" d val d = tx " " d val d = tx "world" d val d = tx " " d in "---" end fun xduce d u = let fun xd acc d u = let val _ = print "xducer receiving...\n" val (x, u) = rx u val _ = print ("xducer got (" ^ x ^ ")\n") in if x = " " then xd "" (tx acc d) u else xd (acc ^ x) d u end val _ = print "xduce starting\n" in xd "" d u end fun takeTwo c = let val _ = print "takeTwo starting\n" val (x, c') = rx c val (y, c'') = rx c' in x ^ " " ^ y end (* f : ('a, 'b) chan -> 'x g : 'a * ('b, 'a) chan -> 'x comp f g : 'x (starts with computation in f) *) fun ccomp f g = callcc (fn k => g (callcc (fn u => throw k (f (Chan u))))); (* u : ('a * ('b, 'a) chan) cont *) (* Chan u : ('a, 'b) chan *) (* f (Chan u) : 'x *) (* k : 'x cont *) (* throw k (f (Chan u)) : _|_ *) (* callcc (fn u => throw k (f (Chan u))) : 'a * ('b, 'a) chan *) (* f : ('a, 'b) chan -> 'x g : ('b, 'a) chan -> 'x comp f g : 'x (starts with computation in f) *) fun comp f g = ccomp f (fn (_,c) => g c); val n = comp takeTwo (fn d => comp (xduce d) source); fun alice c = let val _ = print "blah\n" val (x, c) = sw 1 c val (y, c) = sw 2 c in ("alice", x, y) end; fun bob (p, c) = let val _ = print "blah2\n" val (u, c) = sw (Int.toString p) c val (v, c) = sw (Int.toString u) c in ("bob", Int.toString u, Int.toString v) end; val z = ccomp alice bob;
-
(no subject)
Some further progress cleaning up the https://xkcd.com/1360/ -esque augean stables that is my hard drive. Tomato chicken I made a couple days ago…
-
(no subject)
Did some personal archaeology. Helped a little with laundry. Threw some chicken, onions, tomato, stock, peppers in the slow cooker and hopefully…
-
(no subject)
Dinner with akiva and dannel at nuevo portal in carroll gardens. Ate a pile of chicken stew and rice and beans and maduros, good times. I do miss…
- Post a new comment
- 0 comments
- Post a new comment
- 0 comments