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
#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
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
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
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
5 matches
Mail list logo