Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

AlexKnauth
Copy link
Member

@AlexKnauth AlexKnauth commented Oct 23, 2019

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
Copy link
Member

samth commented Oct 23, 2019

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
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
Copy link
Member

samth commented Oct 23, 2019

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

@AlexKnauth
Copy link
Member Author

AlexKnauth commented Oct 23, 2019

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
Copy link
Member

samth commented Oct 23, 2019

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
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