Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

dynamic interfaces as structural types #4506

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

dynamic interfaces as structural types #4506

CeylonMigrationBot opened this issue Aug 13, 2015 · 5 comments

Comments

@CeylonMigrationBot
Copy link

[@gavinking] 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.

[Migrated from ceylon/ceylon-spec#1400]

@CeylonMigrationBot
Copy link
Author

[@Zambonifofex] 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...

@CeylonMigrationBot
Copy link
Author

[@gavinking]

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.

@CeylonMigrationBot
Copy link
Author

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

@CeylonMigrationBot
Copy link
Author

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

@CeylonMigrationBot
Copy link
Author

[@RossTate] 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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants