It seems like integer? can succeed for ... non-integers? Why doesn't this code type-check?
#lang typed/racket
(define x : Real 134)
(define y : Integer (cond [(integer? x) x]
[else (error "not an integer")]))
It seems like integer? can succeed for ... non-integers? Why doesn't this code type-check?
#lang typed/racket
(define x : Real 134)
(define y : Integer (cond [(integer? x) x]
[else (error "not an integer")]))
You're absolutely right, the
integer?predicate doesn't just succeed for things of type Integer, it also succeeds for inexact reals like3.0. You probably wanted to use the predicateexact-integer?, instead:This code type-checks and runs.
The same goes for
nonnegative-integer?, use insteadexact-nonnegative-integer?.