r/ProgrammingLanguages • u/ThomasMertes • Oct 05 '26
Achieving memory safety
https://seed7.net/papers/memory_safety.htm
14
Upvotes
r/ProgrammingLanguages • u/ThomasMertes • Oct 05 '26
View all comments
Show parent comment
1
u/reflexive-polytope Oct 10 '26
Stopping with a runtime check doesn't it make it any less of a type soundness bug.
The simplest solution is to not allow covariant method argument types to begin with. That's what Java and .NET do. But the price is that implementing binary methods requires so-called F-bounded polymorphism (
class Foo extends Comparable<Foo>), which is ugly, even if you can get used to it.A more sophisticated solution is to divorce the concepts of subclassing and subtyping. A subclass
Baris a subtype of a classFooif and only ifBarobjects can be safely used whereFooobjects are expected. OCaml implements this solution. But most programmers would find this surprising. (The average OCaml programmer has a better understanding of programming languages than the average programmer in general.)