[racket] TR Keyword Args (Lil Help)

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Fri Aug 10 13:54:18 EDT 2012

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.
sam th
samth at ccs.neu.edu

Posted on the users mailing list.