[racket] Why Typed Racket is faster?

From: Sam Tobin-Hochstadt (samth at cs.indiana.edu)
Date: Mon Feb 24 09:30:33 EST 2014

On Mon, Feb 24, 2014 at 9:24 AM, Vincent St-Amour <stamourv at ccs.neu.edu> wrote:
>
>> 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?
>
> That's odd. I'll look into it.

This program doesn't actually have the type ascribed -- if you treat
it as having the second type, it should always return a (Listof
Flonum), but when no arguments are passed it returns a single Flonum.

However, the fix, which is to remove the optionality in the #:multiple
argument in the second branch of the case-> type, doesn't cause it to
typecheck. I think the levels of encoding between keyword functions
and the typechecker will make this hard to do, but Asumu has looked
into keyword functions most recently, and my have ideas.

Sam


Posted on the users mailing list.