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

Filter by
Sorted by
Tagged with
1 vote
1 answer
158 views

Implementing automatic derivation without macros?

In Rust: #[derive(Display)] struct Foo<T>(T); If T conforms to the Display trait, ...
Jw C's user avatar
  • 131
1 vote
1 answer
117 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 ...
gstukelj's user avatar
  • 143
11 votes
1 answer
478 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. ...
apropos's user avatar
  • 897
11 votes
4 answers
299 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" ...
kaya3's user avatar
  • 17.3k
2 votes
2 answers
252 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 ...
Lance's user avatar
  • 695
3 votes
1 answer
69 views

Quantified variables without case-based analysis in traits

In almost every functional language I know of, quantified type variables are identified using case: ...
blueberry's user avatar
  • 2,315
5 votes
3 answers
182 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: ...
Seggan's user avatar
  • 2,603
5 votes
1 answer
107 views

How could a language implement generic traits?

Take C#'s IEnumerable<T> interface. It has a singular requirement: ...
Bbrk24's user avatar
  • 8,857
10 votes
3 answers
559 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: ...
Rydwolf Programs's user avatar