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

dynamic interfaces as structural types #1400

Open
gavinking opened this issue Aug 13, 2015 · 5 comments
Open

dynamic interfaces as structural types #1400

gavinking opened this issue Aug 13, 2015 · 5 comments
Assignees
Labels
Milestone

Comments

@gavinking
Copy link
Member

Currently the only way you can assign a value to a dynamic interface type is by assigning an expression with no type within a dynamic block on JavaScript.

It was suggested here that we let you assign a typed expression, performing a structural type check. For example:

dynamic Named {
    shared formal String name;
}

class Gavin() {
    shared String name = "Gavin";
}

Named gavin = Gavin(); //typechecked, outside of dynamic

I don't see a very good reason to not allow this. The work for structural checking of schemas basically parallels the stuff @quintesse already had to do for native, so it's a problem we've already bitten off.

A change we would have to make would be to disallow runtime type checks like is Named, which currently merely evaluate to false. They should be disallowed at compile time.

To be clear: this would amount to Go-style structural typing.

@gavinking gavinking self-assigned this Aug 13, 2015
@gavinking gavinking added this to the 1.3 milestone Aug 13, 2015
@ghost
Copy link

ghost commented Aug 14, 2015

Why would is conditions be disallowed? Is it because they can't easily be implemented in the JVM?

Also, couldn't then, dynamic interfaces satisfy non-dynamic interfaces?

shared dynamic Foo
satisfies {Anything*}
{
    shared actual String first;
}

Then, two completely unrelated types would be subtypes of Foo if they are subtypes of {Anything*} and the type of their member first is a subtype of String...

@gavinking
Copy link
Member Author

Why would is conditions be disallowed? Is it because they can't easily be implemented in the JVM?

Well, yeah. And they would be very inefficient.

Also, couldn't then, dynamic interfaces satisfy non-dynamic interfaces?

No, I don't think we should allow that because there are some things that you can do with / assume about ordinary interfaces that you can't do with / assume about dynamic interfaces.

@RossTate
Copy link
Member

The first challenge (though maybe surmountable) is making this work for dynamic types that are recursively specified.

@gavinking
Copy link
Member Author

@RossTate ah, good point. Hrm. I asume languages like Go handle that right?

@RossTate
Copy link
Member

I admit, I don't know what Go does. If they do, the challenge I pointed out is much easier for them, since they're type system is much smaller.

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

No branches or pull requests

2 participants