[racket] TR Keyword Args (Lil Help)

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Fri Aug 10 15:43:06 EDT 2012

On Fri, Aug 10, 2012 at 3:34 PM, Ray Racine <ray.racine at gmail.com> wrote:
> Sure, I'll probably sketch out a goodly chunk of Plot into TR this weekend
> and will do that modification.
>
> My little POC of TRing the Hist* procedures ended translating pretty well.
>
> https://gist.github.com/3317104
>
> The only "bump" I'm still seeing is in attempting to leverage Snip%  out of
> typed/mred/mred.
>
> When I try and type
> (plot (Renderer-Tree ... stuff ... -> (U Snip% Void))
>
> running  (test3) fails.

It would be easier for me to tell if you include the error message.
But probably the issue is that you need (Instanceof Snip%), not just
Snip%, which is the type of a *class*, not an object.

> What I have now just stubs def-type Image-Snip% with Any, which isn't that
> bad at all.
>
> Is it because TR is currently invariant with Classes or did I tickle another
> bug here?  Image-Snip% is a sub-type (class) of Snip%.
>
>
> Say if typed/mred/mred explicitly proved a typed Image-Snip% would
> everything work?
>
> Ray
>
>
> On Fri, Aug 10, 2012 at 3:00 PM, Neil Toronto <neil.toronto at gmail.com>
> wrote:
>>
>> 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 ⊥
>>
>>
>> ____________________
>>  Racket Users list:
>>  http://lists.racket-lang.org/users
>
>
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>



-- 
sam th
samth at ccs.neu.edu


Posted on the users mailing list.