Yet static typing does very much catch issues, so I really don't see where you're coming from with this.
Yet static typing does very much catch issues, so I really don't see where you're coming from with this.
what? in a language with ADTs and exhaustiveness checking, accessing a key from an associative array will give you back an Option type and the compiler will force you handle the code path where the key is missing.
unless I've misunderstood what you meant, this is a canonical showcase of what modern static type systems are good for.
and in your parent post:
>a list that must not be empty, etc. No, not even dependent types can guarantee these invariants.
what do you call haskell's NonEmpty then? https://hackage.haskell.org/package/semigroups-0.18/docs/src...
data NonEmpty a = a :| [a]
I think you're underestimating what static types can do. it's funny you mention "blub" in that post ...It's mostly the same with nominative NonEmpty types. Any value the programmer has instantiated with one of NonEmpty's type constructors have type NonEmpty - everything else don't. For sure, you could create a NonEmpty class in Java too, but it would still be up to the programmer to enforce the type's semantic during program execution. If the variable L has type NonEmpty (list) then it's bloody obvious to a programmer that the expression pop(push(push(L, x), y)) also has type NonEmpty. To a compiler figuring that one out is mostly impossible.
Option types serve other purposes, like composability; tracing program flow can determine the points where a nullable type either (a) will always be null, or (b) will never be null, and many type checkers for type systems with nullable types (or, more generally, non-discriminated unions, nullable types are just one example.)