Skip to main content

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

1 vote
1 answer
175 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
  • 241
1 vote
1 answer
148 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
587 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
  • 1,078
11 votes
4 answers
310 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
  • 20k
2 votes
2 answers
328 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
  • 705
3 votes
1 answer
72 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,587
5 votes
3 answers
209 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,753
5 votes
1 answer
127 views

How could a language implement generic traits?

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