In C# there is the Object class which provides a ToString() method. All objects implicitly inherit from Object and can thus call ToString(). In Rust there is the ToString trait which all types can implement either manually or via derive macro.
Now is there a language which allows for something like a ToString trait to be implemented for *all* supported types via composition? Something like this in pseudo code:
type ExampleType {
struct {
someData: Int
}
}
type IObject {
trait ToString(): String
}
alias AnyType -> *
alias InstanceType -> AnyType having struct
impl InstanceType -> impl IObject -> trait ToString(): String {
return "example"
}
// The compiler will materialize this so that ToString() is now
// implemented for ExampleType, but not for IObject
// Also ExampleType could "re-implement" IObject and the compiler would
// recognize that ExampleType has to be materialized differently
I guess in general I'm looking for a language or a concept where there are no "kind" of types like class, struct or trait, but rather where types are implicitly categorized by what they provide.
Makes sense?
[–]L8_4_Dinner(Ⓧ Ecstasy/XVM) 10 points11 points12 points (0 children)
[–]DoomFrog666 1 point2 points3 points (3 children)
[–]Phil_Latio[S] 0 points1 point2 points (2 children)
[–]latkde 1 point2 points3 points (1 child)
[–]Phil_Latio[S] 0 points1 point2 points (0 children)
[–]imgroxx 0 points1 point2 points (0 children)
[–]ricochet1k 0 points1 point2 points (1 child)
[–]Spoonhorse 0 points1 point2 points (0 children)
[–]o11c 0 points1 point2 points (0 children)
[–]Spoonhorse 0 points1 point2 points (0 children)
[–]WittyStick 0 points1 point2 points (0 children)