Skip to content

WIP: Add Type/Predicate and make-positive-predicate - #867

Closed
AlexKnauth wants to merge 3 commits into
racket:masterfrom
AlexKnauth:type-predicate
Closed

AlexKnauth wants to merge 3 commits into
racket:masterfrom
AlexKnauth:type-predicate

Conversation

@AlexKnauth

@AlexKnauth AlexKnauth commented Oct 23, 2019 •

Copy link
Copy Markdown
Member

Addresses #457 by adding Type/Predicate and #:type/predicate as sound versions of what's most useful about Opaque and #:opaque.

  • 1. A type constructor Type/Predicate that takes a predicate id and produces a type. If foo? is a predicate, then (Type/Predicate foo?) produces a type for values that have passed foo? even just once. So if (foo? x) returns #true and then returns #false, x still has type Foo after that.

  • 2. A required/typed keyword [#:type/predicate Foo foo?] that imports the predicate foo? and defines the type Foo as (Type/Predicate foo?). The foo? 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 to foo? with type (-> Any Boolean : #:+ (Type/Predicate foo?))
    • (make-positive-predicate (Opaque foo?)) also produces a predicate equivalent to foo? with type (-> Any Boolean : #:+ (Opaque foo?))
  • 4. Make sure make-predicate errors on Type/Predicate types, with an error message that suggests using make-positive-predicate instead. It should give a warning on Opaque types, similarly suggesting make-positive-predicate instead.

TODO: make-predicate should error on Type/Predicate types, but make-positive-predicate should succeed
@samth

samth commented Oct 23, 2019

Copy link
Copy Markdown
Member

What happens if we just change #:opaque to only have a positive predicate? How much breaks?

I'd really prefer not to add a lot more mechanism here.

@AlexKnauth

Copy link
Copy Markdown
Member Author

If we did that then make-predicate could no longer soundly work on types containing Opaque types. Only make-positive-predicate could.

@samth

samth commented Oct 23, 2019

Copy link
Copy Markdown
Member

That's also true of your proposal, I believe.

@AlexKnauth

AlexKnauth commented Oct 23, 2019 •

Copy link
Copy Markdown
Member Author

Yes, with my proposal make-predicate would be a warning on Opaque types, which would guide programmers toward the sound version. But it wouldn't be an error, so still unsound

TODO: make-predicate should error on Type/Predicate types, but make-positive-predicate should succeed
The exact? field determines whether the contract must defice exactly whether the value has the type.
exact? is true for make-predicate, but false for make-positive-predicate and everything else
@samth

samth commented Oct 23, 2019

Copy link
Copy Markdown
Member

I should also say that this change will definitely require an RFC, and I encourage you to first write that and go through the process before working too much more on the implementation.

@AlexKnauth

Copy link
Copy Markdown
Member Author

Closed to be replaced by #882

@AlexKnauth AlexKnauth closed this Dec 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants