[racket-dev] (round), etc. in Typed Racket

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Sat Dec 11 22:49:28 EST 2010

On Sat, Dec 11, 2010 at 9:47 PM, Robby Findler
<robby at eecs.northwestern.edu> wrote:
> This seems like an unfortunate naming discrepancy.

I agree.  I think the solution is to change Racket, however.  From the
perspective of the type system, inexact integers are useless - they
have no closure properties, don't obey various laws we'd like the
integers to obey, etc.

Changing Racket is tricky, but I think using the `Integer' type for
something useless (it's not even currently represented in the TR type
system) would be a mistake.

> Robby
> On Sat, Dec 11, 2010 at 7:52 PM, Vincent St-Amour <stamourv at ccs.neu.edu> wrote:
>> At Sat, 11 Dec 2010 18:35:17 -0700,
>> Petey Aldous wrote:
>>> I've discovered what may be a bug in the type system of Typed Racket. The
>>> functions that round - (round), (truncate), (ceiling), etc. are typed as
>>> Real, not Integer; however, the result of (integer? (round (* 10e15
>>> (random)))) is consistently true - and the same holds for the other rounding
>>> functions.
>> Typed Racket's Integer type corresponds to racket's exact integers
>> (exact-integer?, not integer?).
>> integer? can return true for floating point numbers:
>> (integer? 1.0) -> #t
>> but exact-integer? cannot.
>> The types for round, truncate, etc. take this into account. For
>> instance, if you round an exact rational, the type of the result will
>> be Integer, whereas if you round a floating point number, you get a
>> Float back.
>>> Is this intentional? If so, why? If it is (or even if it isn't), how can I
>>> transform the result of (random) to an Integer?
>> You can use inexact->exact on the result of round.
>> Vincent
>> _________________________________________________
>>  For list-related administrative tasks:
>>  http://lists.racket-lang.org/listinfo/dev
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/dev

sam th
samth at ccs.neu.edu

Posted on the dev mailing list.