PasteRack.org
Paste # 49759
2014-09-03 14:47:08

Fork as a new paste.

Paste viewed 631 times.


Embed:

...I guess I've figured out cps in typed racket

  1. #lang typed/racket
  2.  
  3. (: cps-ish ( (Ret0 Ret1) (-> Boolean Ret0 Ret1
  4.                               (-> Ret0 Ret0) (-> Ret1 Ret1)
  5.                               (U Ret0 Ret1))))
  6. (define (cps-ish b x0 x1 tail0 tail1)
  7.   (if b (tail0 x0) (tail1 x1)))
  8.  
  9. (cps-ish #t 'hello "world" (lambda (x) x) (lambda (x) x))
  10.  
  11. (define #:∀ (Ret0 Ret1)
  12.   (cps-ish* (b : Boolean) (x0 : Ret0) (x1 : Ret1)
  13.             (tail0 : (-> Ret0 Ret0)) (tail1 : (-> Ret1 Ret1)))
  14.   : (U Ret0 Ret1)
  15.   (define (helper (b : Boolean) (x0 : Ret0) (x1 : Ret1)) : (U Ret0 Ret1)
  16.     (if b (tail0 x0) (tail1 x1)))
  17.   (helper b x0 x1))
  18.  
  19. (cps-ish* #f 'hello "world" (lambda (x) x) (lambda (x) x))

=>