[racket] occurrence typing for case?
I'm not sure what you mean by the typed version of case. The version
of case in TR is the same as the one in untyped racket, so we cannot
change it to only require an identifier. The real solution is to fix
PR 14502, and while it is non-trivial (> 1 hour of work) we mostly
know what needs to be done to fix it.
On Sun, May 11, 2014 at 5:54 PM, Alexander D. Knauth
<alexander at knauth.org> wrote:
>
> On May 11, 2014, at 7:41 PM, Eric Dobson <eric.n.dobson at gmail.com> wrote:
>
> The issue is that there is a temporary variable that has the same
> value as x and TR cannot see that they point to the same location.
> Your implementation of case/type has the same problem. I thought there
> was a bug filed for it but couldn't find it so just filed one.
> http://bugs.racket-lang.org/query/?cmd=view&pr=14502
>
>
> Use this:
> #lang typed/racket
> (require typed/rackunit)
>
> (define-syntax-rule
> (case/type y x-expr
> [t1 body ...] ...)
> (let ([y x-expr])
> (cond [((make-predicate t1) y) body ...] ...))
> )
>
> This worked:
> #lang typed/racket
> (require typed/rackunit)
> (require syntax/parse/define)
>
> (define-simple-macro
> (case/type x:id
> [t:expr body:expr ...+] ...)
> (cond [((make-predicate t) x) body ...] ...)
> )
>
> (define (my-length x)
> (case/type x
> [String (string-length x)]
> [(Listof Any) ((inst length Any) x)]
> ;[VectorTop (vector-length x)]
> ))
> (check-equal? (my-length "12345") 5)
> (check-equal? (my-length '(1 2 3 4 5)) 5)
> ;(check-equal? (my-length #(1 2 3 4 5)) 5)
>
> Would something like that work for the typed version of case?
>