These are my notes and solutions to exercises from the delimited continuations tutorial from the Asai laboratory at Ochanomizu University. Because I could not actually find a way to install OchaOCaml, all of the coding exercises are implemented in Racket.
Update: TypeScript solutions! I was able to successfully translate the solutions into TypeScript, and so each exercise is also now available in TypeScript.
There are some key differences in a Racket implementation however.
The scheme language variant used in this example is not statically type-checked, so none of the code-based solutions address the type based questions in the exercises.
The example solutions use the racket algebraic data type collection. This just lets you construct (and deconstruct) product types using positional fields. There is no type checking, and so anything that goes in will come out.
(data MyType (ConstructorOne ConstructorTwo))
(define one (ConstructorOne 1))
(define two (ConstructorTwo 1 2))
(let ([(ConstructorOne x) one]
[(ConstructorTwo y z) two])
(println x)
(println y)
(println z))
prints:
1
2
3
The reset
and shift
forms in scheme do not take closures as their
argument, they just take a straight up forms to be evaluated, so
there is no need to create a lambda. For example the following OCaml
example in the tutorial.
reset (fun () -> 3 + shift (fun _ -> "hello") - 1)
Would be written in racket as:
(reset (shift _ "hello") -1)