[racket] Predicates for instantiated types in Typed Racket
Hi all,
I think I must be missing something about how Typed Racket predicates
work. If I define a predicate for an instantiated polymorphic structure,
my programs type check fine, but I get runtime errors when I try to use
the predicate, which boil down to "expected procedure, given:
#<make-contract>".
Here's a couple of examples:
#lang typed/racket
(struct: (A) poly ([n : A]))
(define-type Foo (poly Integer))
(define-predicate foo? Foo)
(: foo (Integer -> Foo))
(define (foo i) ((inst poly Integer) i))
;; this type checks, but errors when evaluated
;(foo? (foo 3))
; => procedure application: expected procedure, given: #<make-contract>;
; arguments were: #<poly>
(define-type Bar (poly String))
(define-predicate bar? Bar)
(: bar (String -> Bar))
(define (bar s) ((inst poly String) s))
(define: mixed : (Listof (U Foo Bar))
(list (foo 1) (bar "x") (foo -2) (bar "y")))
;; this type checks, but errors if called
(: filter-foos ((Listof (U Foo Bar)) -> (Listof Foo)))
(define (filter-foos l)
(filter foo? l))
;(filter-foos mixed)
; => filter: expected argument of type <procedure (arity 1)>; given #<make-contract>
So, what am I missing?
Thanks, as always,
Richard