
Guard opaque predicates with an (-> Any Any) contract. This uses the contract generation infrastructure to avoid wrapping struct predicates. Also, relax `any-wrap/c` (the contract used for `Any` in positive position) to allow opaque structures. This also requires an enumeration of all the other kinds of values that TR understands, so that they are not confused with opaque structures. Joint work with @bennn. Closes #202. Closes #203. Closes #241.
19 lines
338 B
Racket
19 lines
338 B
Racket
#lang racket/base
|
|
|
|
;; Pure functions are fine predicates
|
|
|
|
(module untyped racket/base
|
|
(define (color? x)
|
|
(and (memq x '(red green blue)) #t))
|
|
(provide color?))
|
|
|
|
(module typed typed/racket/base
|
|
(require/typed (submod ".." untyped)
|
|
[#:opaque Color color?])
|
|
(color? 'blue)
|
|
(color? 4)
|
|
(struct s ())
|
|
(color? s))
|
|
|
|
(require 'typed)
|