Last active
January 9, 2020 06:58
-
-
Save Nymphium/f0e9044e8fc5f46cd1bf50c68c660907 to your computer and use it in GitHub Desktop.
This file contains 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
#lang racket | |
(require racket/control) | |
(struct spwn (val p) #:prefab #:extra-name Spwn) | |
(define (fcontrol-at p v) | |
(fcontrol (spwn v p))) | |
(define (%-at p th handler) | |
(% (th) (λ (x k) | |
(match x | |
[(Spwn v p~) #:when (eqv? p p~) | |
(handler v k)] | |
[(Spwn v p~) | |
(let [(res (fcontrol-at p~ v))] | |
(%-at p (λ () (k res)) handler))])))) | |
(define (perform eff v) | |
(fcontrol-at eff v)) | |
(define (new-effect) (make-continuation-prompt-tag)) | |
(define ((call-with-shallow-handler eff vh effh) th) | |
(let* [(p (make-continuation-prompt-tag 'return)) | |
(const (λ (x _) x)) | |
(effh~ (λ (x k) | |
(fcontrol-at p (effh x k))))] | |
(%-at p (λ () (vh (%-at eff (λ () (th)) effh~))) const))) | |
; -------- | |
(let* [(eff (new-effect)) | |
(handle- (λ (effh th) | |
((call-with-shallow-handler eff | |
(λ (x) (+ x 3 )) | |
effh) | |
th)))] | |
(handle- | |
(λ (v k) (k (+ v 10000000))) | |
(λ () (handle- | |
(λ (v k) (k (+ v 10000))) | |
(λ () | |
(+ (perform eff 11) (perform eff 13))))))) |
Author
Nymphium
commented
Jan 7, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment