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

Use intersection to handle lax static typing #488

Open
jclark opened this issue Apr 13, 2020 · 0 comments
Open

Use intersection to handle lax static typing #488

jclark opened this issue Apr 13, 2020 · 0 comments
Assignees
Labels
enhancement Enhancement to language design lang Relates to the Ballerina language specification status/idea An idea that is not yet a worked-out proposal
Milestone

Comments

@jclark
Copy link
Collaborator

jclark commented Apr 13, 2020

At the moment, lax static typing is not well integrated into the type system: laxness is not part of the type. This makes it hard to make lax static typing work coherently. There's also no way for users to say whether a type should be laxly typed (this is #198).

The concept of lax static typing is that it is a way to achieve the effect of dynamic typing. The programmer has in mind a particular static type, but has not made it explicit in the program; with a lax type, an expression that would be rejected at compile-time is allowed at compile-time and instead is allowed to produce an error value at run-time.

C# provides this feature using a type dynamic.

One idea is to approach this similarly to readonly (as in #476) using intersection types (#508). We could then define json as:

type json = dynamic & 
  (()|boolean|int|float|decimal|string|json[]|map<json>)

In other words, we are saying laxness becomes a non-primary aspect of type. It is almost like saying values have a dynamic bit, just like they have a read-only bit. But not quite: this should be a compile-time feature. When you do a cast <dynamic>, instead of checking that the value actually has a dynamic bit set, the cast would always succeed. The static type checking would though work exactly as if values had this dynamic bit.

This could potentially provide a basis on which to solve #487.

@jclark jclark added enhancement Enhancement to language design lang Relates to the Ballerina language specification status/idea An idea that is not yet a worked-out proposal labels Apr 13, 2020
@jclark jclark added this to the 2020R2 milestone Apr 13, 2020
@jclark jclark self-assigned this Apr 13, 2020
@jclark jclark changed the title Handle lax static typing similarly to readonly Use intersection to handle lax static typing May 1, 2020
@jclark jclark modified the milestones: Swan Lake dump, Later Jan 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement to language design lang Relates to the Ballerina language specification status/idea An idea that is not yet a worked-out proposal
Projects
None yet
Development

No branches or pull requests

1 participant