Git Product home page Git Product logo

Comments (6)

soc avatar soc commented on May 5, 2024

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.

soc avatar soc commented on May 5, 2024

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 toparent_class`.

I think the next step would be to add the direct implementations of traits to the VM's list of impls.

@dinfuehr Do you have a suggestion at which point this should happen?

from dora.

dinfuehr avatar dinfuehr commented on May 5, 2024

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.

soc avatar soc commented on May 5, 2024

so implementing Default for Option[T] doesn't work

Do you mean "does work", or am I misunderstanding something?

from dora.

dinfuehr avatar dinfuehr commented on May 5, 2024

Oh sorry, I meant that implementing Default for Option[T] doesn't work at the moment.

from dora.

soc avatar soc commented on May 5, 2024

Ahh, ok, thanks, understood!

from dora.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.