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

Filter by
Sorted by
Tagged with
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 ...
Jonas's user avatar
  • 501
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, ...
Jw C's user avatar
  • 233
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 ...
gstukelj's user avatar
  • 163
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. ...
apropos's user avatar
  • 1,236
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" ...
kaya3's user avatar
  • 20.8k
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 ...
Lance Pollard's user avatar
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: ...
blueberry's user avatar
  • 2,597
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: ...
Seggan's user avatar
  • 3,053
5 votes
1 answer
141 views

How could a language implement generic traits?

Take C#'s IEnumerable<T> interface. It has a singular requirement: ...
Bbrk24's user avatar
  • 9,407
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: ...
rydwolf's user avatar
  • 4,582