Open welopino opened 7 years ago
Sorry, I can't really follow you here.
For the first paragraph, you already can override formal/default methods/attributes by simply specifying them via =>
, without repeating the whole method declaration.
Could you add some examples of what your proposal would allow which is currently not allowed?
I'd suggest that an attribute or method of a subclass that has no specified type and that overrides a attribute or method from the superclass or satisfies an interface, should inherit the specification of type(s) and annotation(s) of the superclass attribute or method. This idea is derived from Dart and resembles signatures in ML.
This helps to reduce visual clutter caused by annotations and types. This information is not always needed can be moved from the implementation to an (signature) interface. An IDE can provide type information and annotation as tooltip to the human reader.
This idea is derived from Dart: https://www.dartlang.org/guides/language/sound-dart#field-and-method-inference
This idea resembles signatures in ML languages: "The fundamental constructs of the ML module system are signatures and structures. A signature may be thought of as an interface or specification of a structure, and a structure may correspondingly be thought of as an implementation of a signature." Cited from: https://www.cs.cmu.edu/~rwh/introsml/modules/sigstruct.htm
To help the parser, the superclass or interface must precede the subclass or implementing class within the same compilation unit. As a hint such an interface could be annotated as e.g. 'signature' and it should not contain any implementation.
In ocaml an .mli file that has to precede an .ml file.
For the parser all information about the type of an attribute or method is present before parsing the implementation, because identifiers are unique in ceylon. The parser simply has to carry a map of the names of these 'signature interfaces ... ' within one compilation unit.
When annotations and types are located on the interface instead of the implementing class these informations still are close together in the same file for the human reader. An IDE can provide type information and annotation on hover.
Error messages of the parser need not to change. If type information is not present it is the same error as it used to be. And if an interface is unnecessarily annotated 'signature' there could be a warning.