[racket-dev] Experimenting with generics in TR

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Sun Feb 10 08:55:30 EST 2013

What is the type of `ops-hash` intended to be here?

Sam

On Sat, Feb 9, 2013 at 9:27 PM, Neil Toronto <neil.toronto at gmail.com> wrote:
> I'd like to play around with implementing generics or type classes in Typed
> Racket, but without changing its internals, just to see what it takes. I
> think I could get something pretty decent working if I could get the
> following program to type:
>
>
> (define ops-hash (make-hasheq))
>
> (: set-ring-ops! (All (A) (Symbol (ring-ops A) -> Void)))
> (define (set-ring-ops! name ops)
>   (hash-set! ops-hash name ops))
>
> (: get-ring-ops (All (A) ((ring-member A) -> (ring-ops A))))
> (define (get-ring-ops x)
>   (define name (ring-member-ops-name x))
>   (hash-ref ops-hash name (λ () (error 'get-ring-ops
>                                        "unregistered ring ~a"
>                                        name))))
>
>
> Of course, I can't. In fact, I can't get this to work by writing
> `set-ring-ops!' and `get-ring-ops' in untyped Racket and importing them
> using `require/typed', because the contract system can't prove that the `A'
> in `get-ring-ops' is the same as the `A' in `set-ring-ops!'.
>
> Is there a secret, hidden escape hatch that would allow me to get functions
> with these types and behaviors?
>
> Neil ⊥
> _________________________
>  Racket Developers list:
>  http://lists.racket-lang.org/dev


Posted on the dev mailing list.