WIP: Add Type/Predicate and make-positive-predicate #867
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Addresses #457 by adding
Type/Predicate
and#:type/predicate
as sound versions of what's most useful aboutOpaque
and#:opaque
.1. A type constructor
Type/Predicate
that takes a predicate id and produces a type. Iffoo?
is a predicate, then(Type/Predicate foo?)
produces a type for values that have passedfoo?
even just once. So if(foo? x)
returns#true
and then returns#false
,x
still has typeFoo
after that.2. A required/typed keyword
[#:type/predicate Foo foo?]
that imports the predicatefoo?
and defines the typeFoo
as(Type/Predicate foo?)
. Thefoo?
predicate is imported with type(-> Any Boolean : #:+ Foo)
. It can not have type(-> Any Boolean : Foo)
.3. A new expression form
make-positive-predicate
that takes a type and produces a predicate with only the positive#:+
proposition. So(make-positive-predicate X)
will produce a predicate with the type(-> Any Boolean : #:+ X)
.(make-positive-predicate (Type/Predicate foo?))
produces a predicate equivalent tofoo?
with type(-> Any Boolean : #:+ (Type/Predicate foo?))
(make-positive-predicate (Opaque foo?))
also produces a predicate equivalent tofoo?
with type(-> Any Boolean : #:+ (Opaque foo?))
4. Make sure
make-predicate
errors onType/Predicate
types, with an error message that suggests usingmake-positive-predicate
instead. It should give a warning onOpaque
types, similarly suggestingmake-positive-predicate
instead.