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

Refinement types #238

Open
jclark opened this issue Jun 22, 2019 · 2 comments
Open

Refinement types #238

jclark opened this issue Jun 22, 2019 · 2 comments
Labels
Area/Lang Relates to the Ballerina language specification status/idea An idea that is not yet a worked-out proposal Type/Improvement Enhancement to language design
Milestone

Comments

@jclark
Copy link
Collaborator

jclark commented Jun 22, 2019

The idea is that you can use a limited form of expression to constrain a type. The syntax could look like this:

type positiveInt = int where self > 0;

The difficulty is that static type checking becomes very challenging. How would you tell that the type of positiveInt + positiveInt is a positiveInt? One approach is to use an SMT solver.

See paper "Semantic Subtyping with an SMT Solver" by Bierman, Gordon & Langworthy from Microsoft:

https://www.microsoft.com/en-us/research/wp-content/uploads/2010/12/icfp09i-bierman.pdf

This is probably too researchy for Ballerina at the moment, but I want to have an issue to capture the general concept.

Edited: fully static is too researchy, but we don't have to do that.

@jclark jclark added Area/Lang Relates to the Ballerina language specification status/idea An idea that is not yet a worked-out proposal labels Jun 22, 2019
@jclark jclark added this to the 202x milestone Aug 14, 2019
@jclark
Copy link
Collaborator Author

jclark commented Sep 10, 2020

Better syntax:

type-definition := "type" identifier type-descriptor [type-constraint] ";"
type-constraint :="where" expression

The expression in a type-constraint is boolean expression, in which identifier is bound to a value of the type described by type-descriptor, e.g.

type PositiveInt int where PositiveInt >= 0;

The expression in a type-constraint would be required to be isolated to stop things getting too crazy.

The type-constraints would not be checked statically, but would rather be checked at specific language-defined points, including:

  • when a service remote or resource method is invoked
  • by the langlib xyzWithType functions (e.g. cloneWithType)
  • explicitly when requested by the user using a language-defined mechanism

@jclark
Copy link
Collaborator Author

jclark commented Sep 10, 2020

See also Refinement types in Jolie.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/Lang Relates to the Ballerina language specification status/idea An idea that is not yet a worked-out proposal Type/Improvement Enhancement to language design
Projects
None yet
Development

No branches or pull requests

2 participants