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

Union types in Gypsum #30

Open
jayconrod opened this issue Dec 30, 2016 · 0 comments
Open

Union types in Gypsum #30

jayconrod opened this issue Dec 30, 2016 · 0 comments

Comments

@jayconrod
Copy link
Owner

In Gypsum, it should be possible for a value to have a type that is a union of two or more types. For example:

class Foo
class Bar

def f(b: boolean): Foo | Bar = if (b) Foo() else Bar()

The type Foo | Bar is a union between Foo and Bar. This would be a subtype of both Foo and Bar, and for an instance of this type, it should be possible to call methods or access fields that are found in both types (those inherited from any common base class or trait).

This will be useful for exception handling (Java has something like this) and pattern matching in general. It is necessary for Type.lub to be properly implemented for traits.

Intersection types may also be useful, but I'm not sure when they would be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant