X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=cps_and_continuation_operators.mdwn;h=2c3f35603d9110ed565013c45c68e1c8fb3e6f6c;hp=e3fb42d09954a64bc8c315924fe4d0ae97af5847;hb=c42666baade652387ad72d5109eff241c796edfb;hpb=fff7086c5dec8448c3a5369f3df88b50ffd06e6b diff --git a/cps_and_continuation_operators.mdwn b/cps_and_continuation_operators.mdwn index e3fb42d0..2c3f3560 100644 --- a/cps_and_continuation_operators.mdwn +++ b/cps_and_continuation_operators.mdwn @@ -268,11 +268,13 @@ That won't work because `k 1` doesn't have type `int`, but we're trying to add i This also works and as you can see, delivers the expected answer `101`. -At the moment, I'm not able to get the third example working with the monadic library. I thought that this should do it, but it doesn't type-check: +The third example is more difficult to make work with the monadic library, because its types are tricky. I was able to get this to work, which uses OCaml's "polymorphic variants." These are generally more relaxed about typing. There may be a version that works with regular OCaml types, but I haven't yet been able to identify it. Here's what does work: - # C.(run0 (callcc (fun k -> unit (1,k)) >>= fun (p1,p2) -> p2 (2,unit) >>= fun p2' -> unit (p1,p2')));; + # C.(run0 (callcc (fun k -> unit (1,`Box k)) >>= fun (p1,`Box p2) -> p2 (2,`Box unit) >>= fun p2' -> unit (p1,p2')));; + - : int * (int * [ `Box of 'b -> ('a, 'b) C.m ] as 'b) as 'a = + (2, (2, `Box )) -If we figure this out later (or anyone else does), we'll come back and report. +