3 ms·
Sure. So I would like to know: What is a use case where strong static typing is a major advantage, and where Haskell is clearly better than Rust from a language
by spekcular 5y ago
Sure. So I would like to know: What is a use case where strong static typing is a major advantage, and where Haskell is clearly better than Rust from a language design/feature perspective?
edit: Another question. Is there a language that has stronger static typing than Rust without the weird performance pitfalls and subpar tooling that Haskell has? I can imagine a project for which such features would be useful, but getting over those two issues is difficult.
- deleted 5y ago[deleted]
- the_af 5y ago> What is a use case where strong static typing is a major advantage Writing correct code with fewer bugs. Catching bugs earlier. Not having to write unit tests for things the compiler can figure out for you, leaving you free to write the actual meaningful tests. Making code self-documenting with types, leading to less puzzlement. ... just to name a few.
- simiones 5y agoWhile there may be some correlation between some static typing and less bugs, there definitely isn't a linear relationship: stronger type system => fewer bugs. In particular, strong types past some point start exploding code complexity for any kind of polymorphic code. My favorite example is adding strong typing to linear algebra operations, via units of measure for each element of a matrix. Try to find a library that can multiply matrices where each element can be a different physical quantity (of course, validating first that the two matrices can actually be multiplied) - say, multiplying (1m 2s⁻¹) * (2s⁻¹ 1m)ᵀ = 2m/s + 2m/s = 4m/s; but not allowing (1m 2s⁻¹) * (2m 1s⁻¹)ᵀ, since it would be 2m² + 2s⁻². Even if you can find such a library, it will be significantly more complex than an equivalent linear algebra library that is less strongly typed (one that only handles matrices of numbers, without units of measure).
- the_af 5y agoI didn't claim there is a linear relationship. It's enough for me that there is a relationship. The OP asked "what's the use case" and I gave him several that ring true to me. Whenever I write Python , I wish I was writing Haskell. No need to ask about artificial examples of linear algebra; just my boring day to day code in Python would benefit from having Haskell's type system. And yes, I do know about static typing for Python -- I find it's worse, tooling and effectiveness wise, than an actual static type system.
- simiones 5y agoWell, GP was asking about Haskell vs Rust, not Python; and the discussion before was about Haskell vs Java as well. And the example I gave is not entirely artificial - units of measure are often measured as an advantage of strong type systems, something that could potentially avoid the Ariadne disaster, and I find this common example unconvincing.
- the_af 5y agoThe GP also mentioned Python in another comment, and specifically asked "what about strong type systems", which makes the comparison to Python relevant. > something that could potentially avoid the Ariadne disaster Haskell or any language with modern static typing would definitely have helped. You wouldn't be mixing unit types and confusing them like it happened (if I remember correctly) with the Ariadne. Would it have been enough? I don't know! But it would have helped! Any measure of static and dynamic analysis would have helped for mission critical software, and it's evident the Ariadne had some serious deficits in this regard.