Re: [racket-users] Typed analog of integer-in contract

2015-04-21 Thread Asumu Takikawa
This works though: #lang typed/racket (require mzlib/etc) (define-type NDigit (U 0 1 2 3 4 5 6 7 8 9)) (define-type SDigit (U 'one 'two 'three 'four 'five 'six 'seven 'eight 'nine)) (: f (- NDigit SDigit)) (define (f i) (evcase i [(ann 0 0) (displayln i) 'two] [(ann

Re: [racket-users] Typed analog of integer-in contract

2015-04-21 Thread Matthias Felleisen
#lang typed/racket (define-type NDigit (U 0 1 2 3 4 5 6 7 8 9)) (define-type SDigit (U 'zero 'one 'two 'three 'four 'five 'six 'seven 'eight 'nine)) (: to-string (- NDigit SDigit)) (define (to-string i) (case i [(0) (displayln i) 'zero] [(1) (displayln i) 'zero] [(2) (displayln

Re: [racket-users] Typed analog of integer-in contract

2015-04-21 Thread Leif Andersen
You could use a union type, but I’m not sure if a large union type would work well in terms of performance? I don't think this will work. This takes a long time to run (although I'm not sure how much of this is the macro expansion). Anyway, if it takes this long on a union type with 1

[racket-users] Typed analog of integer-in contract

2015-04-20 Thread Benjamin Greenman
The contract integer-in lets me guarantee an integer is within a certain range. (define/contract (mod3 n) (- integer? (integer-in 0 2)) (modulo n 3)) Is there a similar way to specify a type for an integer range? Or do I need to use a union type? (I'd really like to specify a range

Re: [racket-users] Typed analog of integer-in contract

2015-04-20 Thread Alexander D. Knauth
I’m pretty sure no, although such a type would be nice. If it’s a particular range like Byte, Index, Fixnum, or even something like Byte-Greater-Than-One or Index-that-is-not-a-Byte, then a type already exists, even if it’s not explicitly provided, but otherwise, I don’t think so. You could use