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

experiment: make type system more nominal #711

Closed
wants to merge 1 commit into from

Conversation

hishamhm
Copy link
Member

@hishamhm hishamhm commented Oct 21, 2023

Instead of treating nominal records nominally and all other nominal types structurally, with this commit we treat all nominal types nominally except for unions, which are treated structurally.

Give this branch a try in your codebase and let me know your impressions!

[Marked as "draft" because I do not intend to merge this as-is, as there are no test cases for the different behaviors, etc.]

@github-actions
Copy link

Teal Playground URL: https://711--teal-playground-preview.netlify.app

Instead of treating nominal records nominally and all other nominal
types structurally, with this commit we treat all nominal types
nominally except for unions, which are treated structurally.

Give this branch a try in your codebase and let me know your impressions!
@Frityet
Copy link

Frityet commented Dec 12, 2023

What is the benefit of having a more nominal type system? I am quite new to type theory

@hishamhm
Copy link
Member Author

@Frityet The two main approaches for type system are: structural or nominal.

Structural type systems are like static duck typing: you compare the shapes of data, and if the shapes fit, the types are compatible.

Nominal type systems instead, compare names: if you give things the same names, they're the same, if you give them different names, they're different. Nominal systems can be easier to reason about, and avoid accidental compatibility when different things that aren't meant to be the same end up compatible just because they have the same shape.

In practice, as you combine features such as subtyping and generics, both of them get very complicated. Even in nominal type systems, if you have generics where the type variables support subtyping, that is proven to be computationally undecidable (that means it's mathematically impossible to make a compiler for them that always works!)

For more of the motivations of this PR, please take a look at the discussion at #708

@Frityet
Copy link

Frityet commented Dec 13, 2023

@Frityet The two main approaches for type system are: structural or nominal.

Structural type systems are like static duck typing: you compare the shapes of data, and if the shapes fit, the types are compatible.

Nominal type systems instead, compare names: if you give things the same names, they're the same, if you give them different names, they're different. Nominal systems can be easier to reason about, and avoid accidental compatibility when different things that aren't meant to be the same end up compatible just because they have the same shape.

In practice, as you combine features such as subtyping and generics, both of them get very complicated. Even in nominal type systems, if you have generics where the type variables support subtyping, that is proven to be computationally undecidable (that means it's mathematically impossible to make a compiler for them that always works!)

For more of the motivations of this PR, please take a look at the discussion at #708

Nice! Thank you, the PR worlds great for me

@hishamhm
Copy link
Member Author

hishamhm commented Jan 8, 2024

@Frityet Added these changes to the next branch, along with a bunch of new functionality (mainly interface types!)
https://github.com/teal-language/tl/tree/next

@hishamhm hishamhm closed this Jan 8, 2024
@Frityet
Copy link

Frityet commented Jan 8, 2024

@Frityet Added these changes to the next branch, along with a bunch of new functionality (mainly interface types!)

https://github.com/teal-language/tl/tree/next

Cheers! I was trying out that branch a few weeks ago, and it is extremely promising!

@bjornbm bjornbm mentioned this pull request Jan 9, 2024
10 tasks
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