#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 i) 'zero]
[(3) (displayln i) 'zero]
[(4) (displayln i) 'zero]
[(5) (displayln i) 'zero]
[(6) (displayln i) 'zero]
[(7) (displayln i) 'zero]
[(8) (displayln i) 'zero]
[(9) (displayln i) 'zero]
;; can't get here
[else (displayln (+ i i)) 'one]))
I wish mousing over i would give me more precise types here. Occurrence typing
subtracts 2 ... from i's type but somehow it doesn't work thru case.
On Apr 20, 2015, at 9:09 PM, Benjamin Greenman wrote:
> 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 containing over a
> million integers.)
>
>
> --
> 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 [email protected].
> 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 [email protected].
For more options, visit https://groups.google.com/d/optout.