<div dir="ltr"><div><div>I had thought TR would use types to prune unreachable paths. So something like:<br><br>(: test-fn (Symbol -> Symbol))<br>(define (test-fn y)<br>  (: only-symbol (case-> (Symbol -> Symbol)<br>                         (String -> String)))<br>  (define (only-symbol x)<br>    (if (symbol? x)<br>        x<br>        (error "can't ever get here!")))<br>  (only-symbol y))<br><br>(test-fn 'a)<br><br></div>would get pruned/rewritten before being handed off to the middle end of Racket. Now that I'm writing this I realize that type checking, rewriting, and inlining would have to occur, so I'm not sure why I thought that was the case. Thanks for setting me straight.<br><br></div>-Luke<br><div><div><br><br><div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 22, 2015 at 8:26 PM, Matthias Felleisen <span dir="ltr"><<a href="mailto:matthias@ccs.neu.edu" target="_blank">matthias@ccs.neu.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
<br>
TR is a library-language of R with types and type checking hooked in after macro-expansion is done (the part of the compiler that is relevant). When type checking is done, types disappear so that the middle end of Racket can kick in as before. The macro system of Racket is unaware of types so it cannot dispatch in response to Racket. -- Matthias<br>
<div><div class="h5"><br>
<br>
<br>
On Jan 22, 2015, at 11:39 AM, Luke Whittlesey wrote:<br>
<br>
> Hello,<br>
><br>
> I've been learning TR, but I seem to have gotten myself into a corner that I haven't been able to find a workaround for. I'm looking for some help on how to get TR to perform occurrence typing with promises. Basically I'm trying to dispatch based on type, which works without promises, but fails with promises.<br>
><br>
> For background, this code works::<br>
> ---- begin working code ----<br>
><br>
> #lang typed/racket<br>
><br>
> (define-type Wire Symbol)<br>
> (define Wire? (make-predicate Wire))<br>
> (define-type WireVec (Listof Wire))<br>
> (define WireVec? (make-predicate WireVec))<br>
><br>
> ;; dispatch based on type<br>
> (: Not (case-> (Wire -> Wire)<br>
>                (WireVec -> WireVec)))<br>
> (define (Not wire*)<br>
>   (if (Wire? wire*)<br>
>       (Not-wire wire*)<br>
>       (Not-wirevec wire*)))<br>
><br>
> (: Not-wire (Wire -> Wire))<br>
> (define (Not-wire w)<br>
>   (displayln "received wire")<br>
>   w)<br>
><br>
> (: Not-wirevec (WireVec -> WireVec))<br>
> (define (Not-wirevec w)<br>
>   (displayln "received wirevec")<br>
>   w)<br>
><br>
> ;; test<br>
> (Not 'my-wire)<br>
> (Not (list 'a 'b 'c))<br>
><br>
> ;;; printed results are<br>
> ;received wire<br>
> ;'my-wire<br>
> ;received wirevec<br>
> ;'(a b c)<br>
><br>
> ---- end working code ----<br>
><br>
> When I use the same code as above, but add promises to the basic types, I can no longer create a predicate, so I also can't do occurrence typing. Is there a workaround to be able to perform compile time dispatch based on promise types?<br>
><br>
> ;; define types with promises as well<br>
> (define-type Wire (U (Promise Wire) Symbol))<br>
> (define Wire? (make-predicate Wire))       ; <-- error<br>
> (define-type WireVec (U (Promise WireVec) (Listof Wire)))<br>
> (define WireVec? (make-predicate WireVec)) ; <-- error<br>
><br>
> I understand that a contract can't be generated for something like (Promise Wire), because at runtime a promise can't identify it's payload without forcing it, but it seems like the (Promise Wire) type is available at compile time, so there might be a way to make a compile time dispatch.<br>
><br>
> Thanks,<br>
> Luke<br>
><br>
</div></div>> ____________________<br>
>  Racket Users list:<br>
>  <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br>
</blockquote></div><br></div></div></div></div></div>