Comments (6)
I think the hardest part is deciding how the class syntax should look like.
One problem is that if the class already has an inheritance relationship, the syntax would look kinda weird:
class Foo(...) : Bar(...) <keyword> Comparable {
fun compareTo(rhs: Foo) -> Int = ...
}
It feels like this creates a much stronger visual connection between Bar
and Comparable
than between Foo
and Comparable
, which I believe is undesirable.
One approach would be to use only operators like this (and line :
up with it's use in generics ...
class Foo(...) < Bar(...) : Comparable {
fun compareTo(rhs: Foo) -> Int = ...
}
... but I feel this could create a lot of line-noise and would make reading harder.
On the other hand, I kind of dislike the use of :
for different things, so maybe going the other way around and giving both inheritance and traits a keyword is a good way to tackle this issue:
class Foo(...) extends Bar(...) supports Comparable {
fun compareTo(rhs: Foo) -> Int = ...
}
Based on the exact keyword chosen for direct trait implementations (I'd consider with
or supports
as workable options, but I don't have a too strong opinion on that), the naming scheme of traits would need to be adapted:
... supports Comparable
... supports Sortable
... supports Equals
... supports Identity
... supports Hash
... supports Default
... with Comparable
... with Sortable
... with Equals
... with Identity
... with Hash
... with Default
In both cases there are combinations that sound off.
Maybe there is a consistent selection of names, but I have a hard time figuring it out:
supports: Comparing, Sorting, Equality, Identity, Hashing, Defaulting(?)
with: Comparable, Sortable, Equatable, Identifiable, Hashable, Defaultable
Alternatively, we could use impl
(which raises the question why extends
is not abbreviated, but impl
is:
class Foo(...) extends Bar(...) impl Comparable {
fun compareTo(rhs: Foo) -> Int = ...
}
from dora.
I have worked on this and added the required logic and a struct Supports
to the parser and ast; the Classstruct received a new field next to
parent_class`.
I think the next step would be to add the direct implementations of traits to the VM's list of impl
s.
@dinfuehr Do you have a suggestion at which point this should happen?
from dora.
AFAIU this feature should just be syntactic sugar, so ideally it should be implemented exclusively in the front-end and generate the same data in vm.impls
, but not sure whether ImplData
is ready for this now. So this might have to be changed first.
When you want to work on impl
, IMHO it would be better to work on allowing to implement traits for generic classes (so implementing Default for Option[T] doesn't work).
from dora.
so implementing Default for Option[T] doesn't work
Do you mean "does work", or am I misunderstanding something?
from dora.
Oh sorry, I meant that implementing Default for Option[T] doesn't work at the moment.
from dora.
Ahh, ok, thanks, understood!
from dora.
Related Issues (20)
- Unified Condition Expressions HOT 1
- panic: enum value and `is` HOT 3
- Extending the reach of enums HOT 1
- `toStringHex` and `toStringBinary` strip off leading zeros HOT 1
- Consider turning asserts in @test annotated methods into soft asserts
- Allow defining and calling methods without parentheses
- `--emit-ast` doesn't do anything HOT 2
- The JIT implementation of dora is very cool HOT 1
- reinstate class syntax
- replace `fn` keyword with `fun` keyword
- reinstate `=` for function definition
- implement named parameters
- implement string hash caching
- implement definitional enums
- implement modules (singletons and holders of static functions)
- remove unary operators
- remove bitshift operators
- implement unified condition expressions
- replace procedure syntax with functions having return type `Unit` HOT 1
- How lazy compilation is protected in case of multiple threads? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dora.