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

'as' keyword #64

Open
cooper opened this issue May 12, 2017 · 1 comment
Open

'as' keyword #64

cooper opened this issue May 12, 2017 · 1 comment

Comments

@cooper
Copy link
Owner

cooper commented May 12, 2017

Currently to convert between types there is inconsistency. Methods like toString() and toNumber() exist, but they are not standardized in any way. "Types" such as classes and type interfaces are required to spit out the passed object if it is an instance of the type. This sometimes causes issues with initializers.

A new as keyword would be better. Instead of Type($obj), one would write $obj as Type. It would not be up to the Type to decide what to return. Instead, the keyword will look for two possible means by which the object can be converted:

  • $obj implements a to method which accepts Type as its type argument.
  • Type implements a from class function which accepts $obj as its obj argument.

If the object already conforms to the type, the as implementation should spit out the object unchanged, without even checking for conversion methods.

@cooper
Copy link
Owner Author

cooper commented May 12, 2017

Actually, since classes can be extended from anywhere, I think we should forget the to method and only use from.

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