Since Racket is not Scheme anymore, I think revisiting some of the annoyances of Scheme should be fair game. And, certainly the semantics of integer? is an annoyance. It is useful if you KNOW you are restricted to a range where floating point CAN exactly represent an integer (|x| < 15 or so) and you KNOW you don't have any rounding errors, otherwise it isn't.<br>
<br>For example:<br>> (integer? (+ 1.0e15 0.5))<br>#f<br>> (integer? (+ 1.0e16 0.5))<br>#t<br><br>For Typed Racket, I'm not sure there could ever by a safe use of an integer type with those semantics.<br><br>The semantics of integer? is just a (very limited) subset of what fcmp (<a href="http://fcmp.sourceforge.net/">http://fcmp.sourceforge.net/</a>) does. From the web page, "It is generally not wise to compare two floating-point values for
exact equality, for example using the C == operator. The fcmp package
implements Knuth's suggestions for safer floating-point comparison
operators as a C function." As an aside, fcmp is in the science collection.<br><br>Doug<br><br><div class="gmail_quote">On Sun, Dec 12, 2010 at 7:28 AM, Robby Findler <span dir="ltr"><<a href="mailto:robby@eecs.northwestern.edu">robby@eecs.northwestern.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="im">On Sun, Dec 12, 2010 at 8:15 AM, Sam Tobin-Hochstadt <<a href="mailto:samth@ccs.neu.edu">samth@ccs.neu.edu</a>> wrote:<br>
> On Sat, Dec 11, 2010 at 10:53 PM, Robby Findler<br>
> <<a href="mailto:robby@eecs.northwestern.edu">robby@eecs.northwestern.edu</a>> wrote:<br>
>><br>
>>> Changing Racket is tricky, but I think using the `Integer' type for<br>
>>> something useless (it's not even currently represented in the TR type<br>
>>> system) would be a mistake.<br>
>><br>
>> Well, the change to TR would be to change "Integer" to "ExactInteger"<br>
>> (or similar) presumably, not to add a useless type.<br>
><br>
> I think not having an `Integer' type would be just as bad.<br>
><br>
> Given that (integer? 3.0) => #t, I think there will be an inevitable<br>
> discrepancy between what people expect and what the type system does.<br>
> One of these definitions has to not type check:<br>
><br>
> (: x : Integer)<br>
> (define x 1)<br>
><br>
> (: f : Integer -> Integer)<br>
> (define (f x) (add1 x))<br>
><br>
> (: g : Any -> Integer)<br>
> (define (g x) (assert x integer?))<br>
><br>
> You're suggesting the first one fail, because `Integer' would go away.<br>
> Right now only `g' fails. Adding an `Integer' type that corresponds<br>
> to `integer?' would make `f' fail. My feeling is that the fewest<br>
> people will run into `g', and that it's therefore the right choice,<br>
> since there will be a FAQ about this regardless.<br>
<br>
</div>Well, IMO, given that the main driving design force behind TR is<br>
matching up with Racket that you should not pick a simple convention<br>
for relating Racket predicates to Typed Racket types and stick with it<br>
(unless you can change Racket and, in this case, changing Racket seems<br>
too hard). When you make exceptions to this rule, you'd want to do<br>
that carefully and have big warnings in the docs, etc.<br>
<br>
Another possible compromise point would be to have two types, Integer<br>
and ExactInteger where Integer is a kind of alias for ExactInteger<br>
that the type system itself never prints out, but that it accepts as<br>
input. And perhaps you could even have a #:warn directive (like the<br>
optimization flag) that would print out messages complaining about<br>
using such aliases or something.<br>
<br>
Or would it be possible to have a type Integer that actually matched<br>
what integer? does? That would have the problem that people might<br>
expect optimizations to kick when they wouldn't, but perhaps that's<br>
the least painful point (well, I guess adding more complication to the<br>
number hierarchy type system is its own source of pain ...)<br>
<font color="#888888"><br>
Robby<br>
</font><div><div></div><div class="h5">_________________________________________________<br>
For list-related administrative tasks:<br>
<a href="http://lists.racket-lang.org/listinfo/dev" target="_blank">http://lists.racket-lang.org/listinfo/dev</a></div></div></blockquote></div><br>