[racket] TR: predicate for a Float ?

From: John Clements (clements at brinckerhoff.org)
Date: Fri Jan 6 17:09:48 EST 2012

On Jan 6, 2012, at 9:19 AM, Vincent St-Amour wrote:

> At Fri, 6 Jan 2012 08:47:39 -0800,
> John Clements wrote:
>> 1) Not all of the types printed in (:print-type Foo) are necessarily
>> bound in the user code, right? I tried at one point substituting the
>> result of (:print-type something-or-other) for something-or-other, and
>> got a message about an unbound variable.
> 
> They should be. Which one was unbound? That sounds like a bug.

Your commit message suggests that you figured this out already?

> 
>> 2) It would be great to have a one-sentence description of each
>> type.  In my case, for instance, I clearly did not deduce that the
>> 'single' in 'Positive-Single-Flonum' referred to single-precision.
> 
> I'll add something like that to the docs. Some types are pretty
> self-explanatory, but I agree that the single-precision floating-point
> types are not obvious.

Thanks!

> 
>> 3) What would be *really* awesome would be a tool that accepted a
>> function and a desired output type, and pruned the type of the
>> function so that I could discover what kind of input I had to
>> provide in order to get that kind of output. I find myself
>> repeatedly plowing through enormous types trying to find a clause
>> that will do what I want.
> 
> Would `:query-result-type' do what you want?

Nice! I will say that trying to use it before reading the docs led to some really unpleasant "Internal" error messages:

> :query-result-type
Type Checker: Internal Typed Racket Error : #(struct:exn:fail :query-result-type is only valid at the top-level of an interaction #<continuation-mark-set>) in: here
> (:query-result-type log)
Type Checker: Internal Typed Racket Error : #(struct:exn:fail :query-result-type is only valid at the top-level of an interaction #<continuation-mark-set>) in: here
> (:query-result-type 14)
Type Checker: Internal Typed Racket Error : #(struct:exn:fail :query-result-type is only valid at the top-level of an interaction #<continuation-mark-set>) in: here
> (:query-result-type log Positive-Real)
Desired return type not in the given function's range.
> (:query-result-type log Real)
(case-> (Nonnegative-Inexact-Real -> Inexact-Real) (Inexact-Real-Zero -> Negative-Inexact-Real) (Nonnegative-Exact-Rational -> Real))

Anyhow, I'll certainly be using this tool. Thanks!

John

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4624 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20120106/edb28671/attachment.p7s>

Posted on the users mailing list.