4 ms·
I've always thought that (Oca)ML got it right here: Strict by default, but full lazyiness easily available.
by TylerE 8y ago
I've always thought that (Oca)ML got it right here: Strict by default, but full lazyiness easily available.
- lmm 8y agoAgreed, and I think that's where post-Haskell languages are going (I've already mentioned Idris).
- Bromskloss 8y agoSorry, I'm not too knowledgeable about these things. What is the strict-versus-lazy dichotomy? I wouldn't have thought that they had to do with each other.
- TylerE 8y agoStrict being the opposite of lazy - expressions are executed immediately. Like for instance, given an expression... x = foo(13) In a strict language foo(13) will be evaluated immediately. In a lazy evaluation model, x be 'the result of foo(13)', but foo(13) won't actually be evaluated until some expression forces evaluation, by, for instance, printing the value. This is a gross simplication... lazy can do some really neat things like having functions that return infinite streams. The function would theoretically never terminate, but in practice would be called via something like... for event in infinite_stream() .. do stuff .. if event == TERMINAL_VALUE: break
- Bromskloss 8y agoIs it side effects that creates the need for strictness?
- TylerE 8y agoI wouldn't say so, just efficiency. The cost of booking for laziness isn't free. While it can potentially pay dividends when you're able to avoid evaluation altogether, it isn't free.
- lmm 8y agoI'd say it's the need to reason about evaluation, which might be because of side effects but might also be because of performance (of course that can be regarded as another side effect). Laziness has theoretical advantages but in practice we haven't been able to get away from having to understand how our programs are executed, even in Haskell.
- dvlsg 8y agoIs strict a commonly used word for the opposite of lazy? I've always seen it as "eager", but maybe that's in the context of other programming languages.
- EvilTerran 8y agoIt's commonly used that way, but it's a slightly informal use: being rigorous, "strict" and "non-strict" describe semantic models; whereas "eager" and "lazy" describe evaluation strategies with those semantics. Ie, eager evaluation leads to strict semantics, and lazy evaluation to non-strict semantics.
- nightski 8y agoIt's not so simple in my mind. Sure it sounds good on paper to just throw out laziness and go strict by default, until you realize how much you are giving up by not having laziness the default. My difficulty with Haskell was not that it was lazy, but that it was hard to tell how something would be evaluated without understanding it's entire evaluation model. I think you could have a lazy by default language that makes this a lot more transparent but I'm still thinking about how that might look.
- nerdponx 8y agoAre you familiar with Python's approach to iteration? Obviously Python itself is a world away from Haskell, but its model of lazy and eager iteration is very pleasant to work with, and with Haskell-style typeclasses it would be dead-simple.
- nightski 8y agoAbsolutely, along with .NET's IEnumerable/LINQ. Laziness is definitely possible in a strict language via thunks (similar to how Haskell does it behind the scenes). However I didn't realize what laziness by default makes possible until I spent considerable time in the Haskell ecosystem. It really is a game changer.
- lmm 8y ago> Are you familiar with Python's approach to iteration? Obviously Python itself is a world away from Haskell, but its model of lazy and eager iteration is very pleasant to work with That isn't my experience. As soon as you're in a chain of transformations you have no idea what's lazy or strict.
- nerdponx 8y agoThis is true, but I don't often see people writing code like this in the wild. That's what I mean about it being actually easy with static typing -- you can have the compiler and/or your IDE check for you whether it's a lazy sequence (like a Generator in Python) or not (like a Set, List, etc).