[racket] Typed classes: how to send to a value with union type

From: Alexander D. Knauth (alexander at knauth.org)
Date: Tue Aug 19 14:48:22 EDT 2014

This works fine for me in version 6.1.0.5:
#lang typed/racket
(require typed/racket/snip)
(define snip (new snip%))
(define admin (send snip get-admin))
(define editor (and admin (send admin get-editor)))
(when editor
  (send editor set-caret-owner #f))

On Aug 19, 2014, at 1:32 PM, Neil Toronto <neil.toronto at gmail.com> wrote:

> I'm making a snip in Typed Racket. I have essentially this:
> 
>  (define admin (send this get-admin))
>  (define editor (and admin (send admin get-editor)))
>  (when editor
>    (send editor set-caret-owner #f))
> 
> I get this error:
> 
>  Type Checker: send: type mismatch
>    expected: an object
>    given: (U (Instance Text%) (Instance Pasteboard%)) in:
>      (send editor set-caret-owner #f)
> 
> It's unexpected in the first place because text% and pasteboard% both implement editor<%>. Guarding with (is-a? editor text%) doesn't work. Casting doesn't work because TR can't generate a contract. How do I do this?
> 
> Neil ⊥
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users



Posted on the users mailing list.