Skip to content

Instantly share code, notes, and snippets.

@msullivan
Created September 25, 2025 07:11
Show Gist options
  • Save msullivan/f40250fce8579c0b1e4b2b361a4e3944 to your computer and use it in GitHub Desktop.
Save msullivan/f40250fce8579c0b1e4b2b361a4e3944 to your computer and use it in GitHub Desktop.
how to convert from an ('a -> bot) to 'a cont in sml/nj
(* how to convert from an ('a -> bot) to 'a cont *)
structure CCC =
struct
structure CC = SMLofNJ.Cont
datatype bot = Bot of bot
fun abort (Bot x) = abort x
type 'a cont = 'a -> bot
(* convert using an exception - unsatisfying *)
fun conv_exc (k: 'a cont) =
let
exception E of 'a CC.cont
in
abort (k (CC.callcc (fn k' => raise E k')))
handle E k' => k'
end
(* convert using two callccs *)
fun conv (k: 'a cont) =
CC.callcc (
fn k' : 'a CC.cont CC.cont =>
abort (k (CC.callcc (fn k'' : 'a CC.cont => CC.throw k' k'')))
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment