<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On May 11, 2014, at 7:41 PM, Eric Dobson <<a href="mailto:eric.n.dobson@gmail.com">eric.n.dobson@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">The issue is that there is a temporary variable that has the same<br>value as x and TR cannot see that they point to the same location.<br>Your implementation of case/type has the same problem. I thought there<br>was a bug filed for it but couldn't find it so just filed one.<br><a href="http://bugs.racket-lang.org/query/?cmd=view&pr=14502">http://bugs.racket-lang.org/query/?cmd=view&pr=14502</a><br></blockquote><br><blockquote type="cite">Use this:<br>#lang typed/racket<br>(require typed/rackunit)<br><br>(define-syntax-rule<br> (case/type y x-expr<br> [t1 body ...] ...)<br> (let ([y x-expr])<br> (cond [((make-predicate t1) y) body ...] ...))<br> )<br></blockquote><div><div>This worked:</div><div><font face="Courier New">#lang typed/racket</font></div><div><font face="Courier New">(require typed/rackunit)</font></div><div><font face="Courier New">(require syntax/parse/define)</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">(define-simple-macro</font></div><div><font face="Courier New"> (case/type x:id</font></div><div><font face="Courier New"> [t:expr body:expr ...+] ...)</font></div><div><font face="Courier New"> (cond [((make-predicate t) x) body ...] ...)</font></div><div><font face="Courier New"> )</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">(define (my-length x)</font></div><div><font face="Courier New"> (case/type x</font></div><div><font face="Courier New"> [String (string-length x)]</font></div><div><font face="Courier New"> [(Listof Any) ((inst length Any) x)]</font></div><div><font face="Courier New"> ;[VectorTop (vector-length x)]</font></div><div><font face="Courier New"> ))</font></div><div><font face="Courier New">(check-equal? (my-length "12345") 5)</font></div><div><font face="Courier New">(check-equal? (my-length '(1 2 3 4 5)) 5)</font></div><div><font face="Courier New">;(check-equal? (my-length #(1 2 3 4 5)) 5)</font></div></div><br></div>Would something like that work for the typed version of case? <div><br></div></body></html>