Skip to content

Instantly share code, notes, and snippets.

@kmicinski
Created September 7, 2019 22:06
Show Gist options
  • Save kmicinski/28bbbd6810a991cf47164ed6babd1dc8 to your computer and use it in GitHub Desktop.
Save kmicinski/28bbbd6810a991cf47164ed6babd1dc8 to your computer and use it in GitHub Desktop.
;; Small example of pseudo-algebraic effects in Racket
#lang racket
(define handler-tag (make-continuation-prompt-tag 'handler))
;; Handler
(define ((handler x) k)
(displayln (format "giving back value ~a" x))
(call-with-continuation-prompt
(lambda () (k x))
handler-tag
(handler (+ x 1))))
(call-with-continuation-prompt
(lambda ()
(define (getnext)
(call-with-composable-continuation
(lambda (k)
(abort-current-continuation handler-tag k))
handler-tag))
(let* ([x (+ 1 (getnext))]
[y (+ 1 (getnext))])
(+ 1 (getnext))))
handler-tag
(handler 0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment