[racket] Why Typed Racket is faster?

From: WarGrey Gyoudmon Ju (juzhenliang at gmail.com)
Date: Mon Feb 24 00:51:30 EST 2014

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

(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/deef126c/attachment.html>

Posted on the users mailing list.