<div dir="ltr"><div>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></div>;; define types with promises as well<br><div>(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>