[racket] Ad-hoc polymorphism in Typed Racket

From: Vincent St-Amour (stamourv at ccs.neu.edu)
Date: Mon Feb 14 16:57:25 EST 2011

At Mon, 14 Feb 2011 16:42:52 +0000,
Noel Welsh wrote:
> What's the story for ad-hoc polymorphism in Racket?

I'm assuming you mean Typed Racket.

For the built-in functions that are currently supported by TR, the
ad-hoc polymorphism should work. If you want to write your own ad-hoc
polymorphic functions, you can give them types constructed with the
case-lambda type constructor (which is not the same thing as Racket's
case-lambda macro):
http://docs.racket-lang.org/ts-reference/index.html?q=case-lambda#%28form._%28%28lib._typed/racket/base..rkt%29._case-lambda%29%29

In git, you can also use case-> as a synonym for case-lambda.

> In particular, I'd
> like to use the dict library.

The dict library is not currently supported. The main problem is that
I'm not aware of a way to express the fact that a (Vectorof X) is a
(Dictof Integer X) in TR's type system, which currently makes dict
operations untypeable. We could give them types that exclude vectors,
though.

Would that be an acceptable solution for you?

Vincent


Posted on the users mailing list.