[racket] occurrence typing for case?
Are you using head from the last day or so. I recently pushed fixes for
multiple annotations on the same form. If so can you file a minimal test
case as a bug?
On May 11, 2014 6:15 PM, "Alexander D. Knauth" <alexander at knauth.org> wrote:
> I tried this:
> (define-syntax-rule
> (case/type x-expr
> [t body ...] ...)
> (let ([x x-expr])
> (cond [((ann (make-predicate t) (Any -> Boolean : #:+ (t @ x-expr) #:-
> (! t @ x-expr)))
> x)
> body ...]
> ...))
> )
> But it gave me these errors:
> . Type Checker: type mismatch
> expected: (-> Any Boolean)
> given: (-> Any Boolean : String) in: (make-predicate t)
> . Type Checker: type mismatch
> expected: (-> Any Boolean)
> given: (-> Any Boolean : (Listof Any)) in: (make-predicate t)
> Even though I put the filters in, and if it’s ignoring my filters, then
> shouldn’t (-> Any Boolean : Type) be a subtype of (-> Any Boolean)?
>
> On May 11, 2014, at 8: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?
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140511/130c7388/attachment.html>