Replies: 1 comment
-
Member resolutionI'm hesitant on this, but I think that unlike Java's interface, the implementation of a trait should be kept separate from a type's own member functions. For instance
The benefit of this is to reduce method conflicts (since any type can be opened to implement any trait at anytime) and to explicitly keep capabilities decoupled from the type's definition. However it can also be very cumbersome, as invoking a trait method on a value requires a type variable instantiated to the value's type. In the above example, |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Virgil lacks a notion of interface/capability at the moment, which makes decoupling difficult when writing programs. I have some ideas based on the design of doc/ideas/Traits.v3, and would love some feedback!
Overview
Grammar
This proposal introduces two top-level declarations:
trait
andimpl
.A
trait
defines a set of function signatures that specify shared behavior which types can opt into. Atrait
block declares required methods without providing implementations.An
impl
defines how a type implements a trait by providing concrete implementations for the trait’s declared methods.Type variables' declaration can include an optional trait constraint to specify that the variable can only be instantiated with a type implementing the trait:
Beta Was this translation helpful? Give feedback.
All reactions