[racket] TR Keyword Args (Lil Help)
On 08/10/2012 11:54 AM, Sam Tobin-Hochstadt wrote:
> On Fri, Aug 10, 2012 at 1:38 PM, Ray Racine <ray.racine at gmail.com> wrote:
>> Here https://gist.github.com/3315984
>>
>> The first (test1) works fine. Note it uses a KW arg.
>>
>> However, (test2) fails. I thought it was the complexity of the first arg
>> that I was getting wrong. But when the KW #:label is commented out it works
>> fine.
>
> What's happening here is that vectors don't subtype the way lists do,
> so (Vector Symbol Flonum) isn't an appropriate value when you need a
> (Vector Any (U Real False Interval)). This isn't a problem when you
> don't have the keyword argument, because Typed Racket can figure out
> the needed types from the type of `discrete-histogram`, and so gives
> the vector literals appropriate types. However, TR doesn't currently
> manage to propagate this information when looking at keyworded
> applications, which are much more complex when expanded. Thus the
> behavior you're seeing.
>
> If we give TR a little help here, then this works:
>
> (define: lst : (Listof (Vector Any (U Real False Interval)))
> (list #(A 1.0) #(B 2.0) #(B 3.0) (vector 'C (ivl 0.5 1.5))))
>
> (define (test2)
> (plot (discrete-histogram lst #:label "Hello")))
>
> One way that `plot` could make this easier would be to support lists
> in addition to vectors for histogram data.
That wouldn't be hard to change. The contract and function are both
defined in the file "plot/plot2d/rectangle.rkt". You want to take a
crack at it, Ray? :)
You should only have to change the contract of `cat-vals' in
`discrete-histogram' (to se `or/c'), and change the match pattern that
destructures it to (list (or (vector cats ys) (list cats ys)) ...).
Neil ⊥