3 ms·
> Haskell won’t let you use a wrong type in a container Could you elaborate? Java should throw a runtime exception for mismatches.
by azth 5y ago
> Haskell won’t let you use a wrong type in a container
Could you elaborate? Java should throw a runtime exception for mismatches.
- josephcsible 5y agoThe key word in your post is "runtime". Haskell will prevent that bug at compile time instead.
- azth 5y agoActually, I was thinking of covariant arrays. The compiler should prevent issues at compile time for generic collections, same as Haskell.
- kaba0 5y agoThat’s false. Java’s generics are sound, you can’t introduce runtime type errors without casting (which is also true of haskell)
- TheDong 5y agoAs a pointless pedantic nit, Java's type-system is unsound: https://io.livecode.ch/learn/namin/unsound https://io.livecode.ch/learn/namin/unsound But realistically, the above doesn't matter. What actually matters is that you often _do_ have to cast at runtime in java, so it's somewhat common to hit type errors at runtime in practice. Haskell's type-system makes runtime type casting both less necessary, and vanishingly rare, meaning such runtime cases are practically never hit. The above is at least true from my personal anecdotal experience.
- kaba0 5y agoAs far as I know that unsoundness “hack” no longer work. Hm, could you please show me where you had to cast? Long ago, some resource/service lookup did require casting, but my anecdotal experience is that there really is no common area where I have to cast anything anymore.