[racket] Ad-hoc polymorphism in Typed Racket

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Tue Feb 15 08:47:12 EST 2011

On Tue, Feb 15, 2011 at 7:02 AM, Noel Welsh <noelwelsh at gmail.com> wrote:
> So this isn't really ad-hoc, is it? I can't extend the type in another
> module (typically done with structure properties in Racket). Anyway, a
> union type will do for me, for now.

It's ad-hoc for me, but not for thee.  :)

We have a story for ad-hoc polymorphism involving `case->', but that's
fixed rather than user-extensible.  The kind of extensible ad-hoc
polymorphism that struct properties provide (and that is provided by
typeclasses in Haskell) is not currently supported in Typed Racket --
I expect that figuring out the right type system for struct properties
will require new research.

> Cheers,
> N.
> On Mon, Feb 14, 2011 at 9:57 PM, Vincent St-Amour <stamourv at ccs.neu.edu> wrote:
>> 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
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users

sam th
samth at ccs.neu.edu

Posted on the users mailing list.