I tried this approach with Racket 6.5 and still get the type checker error when 
trying to call the continuation after it has been set.

#lang typed/racket

(define-type EmptySet (U)) 

(: d-or-s (U False (-> Number EmptySet))) 
(define d-or-s #f) 

(: double-or-same (-> Number Number)) 
(define (double-or-same x) 
 (call/cc (lambda ({c : (-> Number EmptySet)}) 
            (set! d-or-s c) 
            (+ x x)))) 

> (double-or-same 10)
- : Number
20
> (d-or-s 1)
. Type Checker: Cannot apply expression of type (U False (-> Number Nothing)), 
since it is not a function type in: (d-or-s 1)
> d-or-s
- : (U False (-> Number Nothing))
#<continuation>

Not sure why the type checker is complaining that d-or-s is not a function type.

On Tuesday, August 30, 2016 at 2:02:18 AM UTC+5:30, Matthias Felleisen wrote:
> Continuations don’t return. In a set-oriented type system this means their 
> result type is the empty set: 
> 
> #lang typed/racket
> 
> (define-type EmptySet (U))
> 
> (: d-or-s (U False (-> Number EmptySet)))
> (define d-or-s #f)
> 
> (: double-or-same (-> Number Number))
> (define (double-or-same x)
>  (call/cc (lambda ({c : (-> Number EmptySet)})
>             (set! d-or-s c)
>             (+ x x))))
> 
> 
> > On Aug 29, 2016, at 2:18 PM, Sourav Datta <soura.ja...@gmail.com> wrote:
> > 
> > Hey everyone,
> > 
> > I am a beginner in Racket and recently learned the basic concepts of 
> > continuations. I like Racket's support of multiple types of continuations 
> > as opposed one type in Scheme. Recently I also started learning about typed 
> > Racket. My problem is, I am not sure how I can annotate a continuation in a 
> > typed racket program. For example, when trying to annotate the below code:
> > 
> > #lang racket
> > 
> > (define d-or-s #f)
> > 
> > (define (double-or-same x)
> >  (call/cc (lambda (c)
> >             (set! d-or-s c)
> >             (+ x x))))
> > 
> > in typed racket, I can see that double-or-same function can have type 
> > (Integer -> Integer). But what should be the type of the variable do-or-s? 
> > If it is Any, then it cannot be called like a function after the 
> > continuation is set to it. So basically my question is how can we type 
> > annotate different types of continuations starting from a simple one like 
> > the above? Also a pointer to the relevant section in typed racket docs 
> > would be great.
> > 
> > Thanks!
> > 
> > -- 
> > You received this message because you are subscribed to the Google Groups 
> > "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an 
> > email to racket-users+unsubscr...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to