Created
September 25, 2025 07:11
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (* 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