Questions tagged [traits]
For questions about design and implementation of traits, a code reuse approach where defined sets of methods can be used to extend a class or type
10 questions
5
votes
3
answers
901
views
How are existential types different from Rust's traits?
I am investigating ways to add some form of abstract data types to a toy language.
I was reading Graydon Hoare's The Rust I Wanted Had No Future, in which he talks about existential types. I have not ...
1
vote
1
answer
182
views
Implementing automatic derivation without macros?
In Rust:
#[derive(Display)]
struct Foo<T>(T);
If T conforms to the Display trait, ...
3
votes
1
answer
217
views
Expressing runtime constraints with trait-bounds
I've recently listened to Corecursive episode with John A De Goes and there's one thing that really got me thinking: the idea of type class laws pertaining to performance guarantees. The example ...
11
votes
1
answer
734
views
Typeclasses, traits, interfaces, protocols: is there any consistent terminology?
Many languages have some form of expressing "user-defined duck typing": defining a type by its behavior, rather than anything about the structure or data of an instance of the type itself. ...
11
votes
4
answers
319
views
Approaches to enforcing contracts for standard user-definable traits
Many languages have some user-definable traits, interfaces or protocols with special status in the language's semantics or standard library, for which there is some kind of "contract" ...
2
votes
2
answers
397
views
Architecture for overriding "trait" implementations many times in different contexts?
I just asked this question about Rust: Is it possible to create a default trait implementation in Rust, and then override that trait implementation somewhere else? My problem is, in my custom lang, I ...
3
votes
1
answer
74
views
Quantified variables without case-based analysis in traits
In almost every functional language I know of, quantified type variables are identified using case:
...
5
votes
3
answers
236
views
How can I reconcile “all functions are variables” with a typeclass type system?
In my WIP language, all functions are really just variables with a callable type. That is, a function call foo(bar) is parsed into the following AST:
...
5
votes
1
answer
141
views
How could a language implement generic traits?
Take C#'s IEnumerable<T> interface. It has a singular requirement:
...
11
votes
3
answers
1k
views
What are the pros and cons of traits in comparison with interfaces?
In Rust, structs and enums may implement any number of traits, which specify certain functions. When a struct/enum implements a trait, this is where the functions are defined:
...