[racket] Typed Racket Performance Optimization

From: Ray Racine (ray.racine at gmail.com)
Date: Thu May 10 08:55:06 EDT 2012

It was late... but the penny dropped this morning.   Consider the domain of
log (x) for x<0.

On Thu, May 10, 2012 at 8:38 AM, Vincent St-Amour <stamourv at ccs.neu.edu>wrote:

> As Neil said, `fllog' is guaranteed to return floats.
>
> If you want to know for which input types `log' has a return type of
> `Float', you can use `:query-result-type' at the TR REPL.
>
>    -> (:query-result-type log Float)
>    (case-> (Nonnegative-Flonum -> Float) (Float-Zero -> Negative-Float))
>
> If you can't restrict the input type, the solution you mention (adding a
> runtime assertion) is perfectly fine, but does involve a check at runtime.
>
> Vincent
>
>
> At Wed, 9 May 2012 23:52:42 -0400,
> Ray Racine wrote:
> >
> > [1  <multipart/alternative (7bit)>]
> > [1.1  <text/plain; ISO-8859-1 (7bit)>]
> > The Typed Racket Performance button in DrRacket informs me that (log v)
> > returns a Complex type, despite all its arguments being reals and that
> if I
> > do not want or expect a complex number as results, I mam restrict the
> type
> > of the arguments.  How does one do that?
> >
> > #lang typed/racket/base
> >
> > (: real-log (Float -> Float))
> >  (define (real-log v)
> >    (assert (log v) flonum?))
> > [1.2  <text/html; ISO-8859-1 (quoted-printable)>]
> >
> > [2  <text/plain; us-ascii (7bit)>]
> > ____________________
> >   Racket Users list:
> >   http://lists.racket-lang.org/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120510/06e896cc/attachment-0001.html>

Posted on the users mailing list.