Skip to content
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

Feat: Predicate types #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

MikaelMayer
Copy link
Member

No description provided.

Copy link
Collaborator

@RustanLeino RustanLeino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice idea and an excellent discussion.

Comment on lines +164 to +165
- For every subset type `MyType`, we could also generate by default a predicate with the name `MyType?` that has the same constraint.
That might actually be even simpler, but then there would be no control over the predicate like `{:opaque}` and `reveal`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of various alternatives, I think this is the strongest contender.

[drawbacks]: #drawbacks

* It feels odd to have restrictions on a predicate so that it becomes a type.
* It might be even more confusing for newcomers.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To teach beginners, I'm guessing it will be preferable to first teach about subset types and about predicates. When those two concepts are clearly understood, one can introduce predicate type, which then acts just like a shorthand.

# Prior art
[prior-art]: #prior-art

This feature to combine both the predicate and a subset type in a single construct does not exist in other programming languages, as far as I know.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A related issue are Dafny's least predicates, which are predicates in Dafny and are data in Coq (declared as Inductive).

The theorem prover PVS has predicate subtypes. I'm unsure, but it may also have a syntax that lets you combine the predicate and the type (either like the predicate type here or as an Odd? predicate that is automatically generated from a type Odd, like in the example below).

# Motivation
[motivation]: #motivation

The last snippet above is very common: We define a predicate, and use that predicate to define a subset type.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another common idiom is

datatype D_ = ... {
  predicate Valid() { ... }
}
type D = d: D_ | d.Valid()

Does predicate type offer any advantage here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good question. It would, but only if we were able to define types in datatype definitions, e.g.

datatype D = ... {
  predicate type Valid() { ... }
}

function f(d: D.Valid) { ... }

that would desugar to

datatype D = ... {
  predicate Valid() { ... }
  static type Valid = d: D | d.Valid();
}

function f(d: D.Valid) { ... }

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.

None yet

2 participants