4 ms·
Laziness is "cool", but is it really needed? I don't know any other commonly known languages that have that as a feature. Is it needed in general, or is it need
by galaxyLogic 4y ago
Laziness is "cool", but is it really needed? I don't know any other commonly known languages that have that as a feature. Is it needed in general, or is it needed in Haskell in particular?
Same thing seems to apply to monads. Haskell programmers use them a lot but other languages seem to work just fine without them.
So my guess is that many of the special features of Haskell are solutions to problems you will have if you insist that language is lazy and pure.
- nequo 4y agoThere is the argument that lazy evaluation improves composability and thus code reuse.[1] Edward Kmett also described how he uses laziness on Reddit sometime ago.[2] [1] http://augustss.blogspot.com/2011/05/more-points-for-lazy-evaluation-in.html http://augustss.blogspot.com/2011/05/more-points-for-lazy-ev... [2] https://www.reddit.com/r/haskell/comments/l98v73/comment/glgun65/ https://www.reddit.com/r/haskell/comments/l98v73/comment/glg...
- munchler 4y agoThere are definitely scenarios where laziness is crucial. Haskell is the only mainstream language I know of where laziness is the default, but many languages offer laziness when needed. (E.g. IEnumerable interface in C#.) Monads are essential for "effectful" programming in a functional language. Imperative languages don't need monads, because everything they do is effectful (which leads to unnecessary side effects, and from there to a plethora of errors).
- epgui 4y agoI believe clojure has laziness out of the box as well. While both languages are functional, in contrast to Haskell, clojure doesn't have functors or monads. My understanding is that the same problem is essentially solved in a different way with macros.
- kqr 4y agoThe common argument goes that "laziness is not the best choice for all problems, but defaulting to it forces you to make some hard decisions (referential transparency, immutability, controlled effects, control structures as first-class citizens) that are beneficial for a large class of problems." In other words, you don't necessarily want laziness for its own sake (though sometimes you do) but you do want it for its second order benefits. Could you get those benefits without laziness? Yes, you could. But in the history of programming languages that has happened very rarely, because under strictness it is very easy and tempting to sneak in a little mutability or uncontrolled effects. Under laziness you can't get away with that.
- galaxyLogic 4y agoBut I thought you can write mutable code also in Haskell, no?
- josephcsible 4y agoOther languages have monads too. They just don't call them that, and give each individual monad's bind operation its own name instead of having a single interface they all share. For example, std::optional in C++ is a monad, with and_then being the monadic bind operation, arrays in JavaScript are monads, with flatMap being the monadic bind operation, and async functions are monads, with await being the monadic bind operation.