Re:Are dynamic languages going to replace static languages? ...
by eloisius on Wednesday August 04, 2021 @03:05AM
(#28058111)
I'm probably way in over my head with making a good case for how this resembles dynamic languages, but what I had in mind was trait objects. You can box a struct and refer to it as a trait object (aka type erasure). Thereafter, the receiver doesn't care _what_ concrete implementation it gets, just that it implements a certain trait.
[ Parent
| on HN ]
Re:Are dynamic languages going to replace static languages? ...
by 4ad on Wednesday August 04, 2021 @05:06AM
(#28058825)
What you describe are existential types, a feature that every statically-typed language with parametric polymorphism has, either through some explicit syntactic feature (Rust traits, Haskell type classes, ML modules), or even without, as from basic logic and the Curry–Howard correspondence you can always encode an existential using universals.
∃a.P(a)
----------------- Remove-Exist
∀b.(∀a. P(a)→b)→b
Some static languages had existentials even before they got parametric polymorphism (Go interfaces). This is why we could do so much in Go without generics!
Re:Are dynamic languages going to replace static languages? ...
by lmm on Wednesday August 04, 2021 @03:28AM
(#28058266)
Yeah that's traditional subtyping, not a dynamic language thing at all.
Re:Are dynamic languages going to replace static languages? ...
by 4ad on Wednesday August 04, 2021 @05:08AM
(#28058837)
Rust traits are not subtyping, Rust's type system is principal (although with subtyping you could achieve the same thing as described by the OP, e.g. in C++, C#, etc, which only have subtyping but no existentials exposed as a syntactic feature).