[racket] Why Typed Racket is faster?

From: WarGrey Gyoudmon Ju (juzhenliang at gmail.com)
Date: Mon Feb 24 01:07:56 EST 2014

Two screen snapshots about the dramatics:
[image: Inline image 1][image: Inline image 2]


On Mon, Feb 24, 2014 at 1:51 PM, WarGrey Gyoudmon Ju
<juzhenliang at gmail.com>wrote:

> Does RVM  know the type information at runtime? Is typed racket just a
> front-end parser (target to contracts)? In theory is it possible to
> manually optimize untyped racket to make it as fast as the typed one in
> most cases?
>
> To ignore the developing features, do we lose any expressivenesses?
>
> (lambda ([μ 0.0] [σ 1.0] #:multiple [p 1])
>    (define samples (flnormal-sample μ σ p))
>    (apply  values (flvector->list samples))
>
> This example returns non-fix-length multiple values,  it seems impossible
> to annotate its type.
> It took me hours and hours to enumerate all possible ways but still
> unsolved.
>
> (define: random-gaussian : (case-> [[#:mean Flonum] [#:stddev Flonum]
> [#:multiple False] -> Flonum]
>                                    [[#:mean Flonum] [#:stddev Flonum]
> [#:multiple Index] -> (Listof Flonum)])
>   {lambda {#:mean [μ 0.0] #:stddev [σ 1.0] #:multiple [p #false]}
>     (define: samples : FlVector (flnormal-sample μ σ (if (false? p) 1 p)))
>     (cond [(false? p) (flvector-ref samples 0)]
>           [else (flvector->list samples)])})
>
> Actually, DrRacket complains about (Values Flonum)
> So 'multiple values' is evil!
>
> Keyword argument is also the optional one, it's good for stopping (case->)
> becoming too complexity. But why not (false? p) tells Typed Racket to
> choose the first function types?
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140224/3af0fcbb/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot-typed.1.png
Type: image/png
Size: 35161 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20140224/3af0fcbb/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot-typed.rkt - DrRacket*.png
Type: image/png
Size: 47072 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20140224/3af0fcbb/attachment-0003.png>

Posted on the users mailing list.