Skip to content

Instantly share code, notes, and snippets.

@takikawa
Created November 2, 2012 18:46
Show Gist options
  • Save takikawa/4003510 to your computer and use it in GitHub Desktop.
Save takikawa/4003510 to your computer and use it in GitHub Desktop.
Typed prompt & abort
#lang typed/racket
(: pt (Prompt-Tag String (Integer -> Integer)))
(define pt (make-continuation-prompt-tag))
(call-with-continuation-prompt
(λ () (string-append "foo" (abort-current-continuation pt 5)))
pt
(λ: ([x : Integer]) x))
(: pt2 (Prompt-Tag Integer ((Integer -> Integer) -> Integer)))
(define pt2 (make-continuation-prompt-tag))
(call-with-continuation-prompt
(λ () (+ 1 (call-with-composable-continuation
(λ: ([k : (Integer -> Integer)])
(abort-current-continuation pt2 k))
pt2)))
pt2
(λ: ([f : (Integer -> Integer)]) (f 5)))
;; macro operators
(require (except-in racket/control
fcontrol))
(: pt3 (Prompt-Tag Integer ((-> Integer) -> Integer)))
(define pt3 (make-continuation-prompt-tag))
;; macro expansion has untyped functions
#;
(% (+ 1 (control-at pt3 k 5))
(λ: ([f : (-> Integer)]) (f))
#:tag pt2)
(require/typed
racket/control
[fcontrol
(Integer [#:tag (Prompt-Tag Integer (Integer (Integer -> Integer) -> Integer))]
-> Integer)])
(: pt4 (Prompt-Tag Integer (Integer (Integer -> Integer) -> Integer)))
(define pt4 (make-continuation-prompt-tag))
(% (+ 1 (fcontrol 5 #:tag pt4))
(λ: ([v : Integer] [k : (Integer -> Integer)])
(k v))
#:tag pt4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment