3 ms·
While its true that lazy evaluation makes it harder to think about performance (specially memory use), the flipside is that it makes it easier to reason about p
by ufo 14y ago
While its true that lazy evaluation makes it harder to think about performance (specially memory use), the flipside is that it makes it easier to reason about programs at a higher level and you have more freedom when defining abstractions.
For example, in Haskell you can freely rewrite common subexpression with a let whenever you want and in whatever order you want.
--original
(f x) ... (f x)
--let
let y = f x in y ... y
On the other hand, if your language has side effects these sort of transformations are not always safe.
- plinkplonk 14y agohaving side effects and having lazy evaluation are distinct features though. One can conceive of a strictly evaluated haskell-like which isolates side effects in monads and is still largely composed of pure functions.
- tome 14y agoOne can conceive of it, and yet it's never been done. Curious.
- nilkn 14y agoThere is Idris: http://idris-lang.org/ http://idris-lang.org/ It seems similar to what plinkplonk is talking about.
- tome 14y agoHmm, I always thought of Idris, Coq and Agda as proof assistants rather than programming languages, but perhaps that's just me being unimaginative.
- gtani 14y agowhat about disciple and mu ? http://stackoverflow.com/questions/10784124/non-lazy-branch-of-ghc http://stackoverflow.com/questions/10784124/non-lazy-branch-... http://anil.recoil.org/papers/2011-cufp-scribe-preprint.pdf http://anil.recoil.org/papers/2011-cufp-scribe-preprint.pdf
- tome 14y agoI'm not really sure how "pure" Disciple can be considered to be, and it doesn't use monads does it? Perhaps I'm being ignorant though. Mu is a great example. I wish there was more information about it publically available.
- colanderman 14y agoYes it has. Mercury is a perfect example of a purely functional language which is not lazy. I/O is made functional via a uniqueness typing system.
- tome 14y agoRight, so it uses uniqueness typing and not monads presumably.
- ufo 14y ago> having side effects and having lazy evaluation are distinct features though Fair enough, but lazyness also plays nicer with things like `if` and `&&` that comput things lazily. (Without lazyness you need to add lots of wrapper anonymous functions). Another thins is that, from a hystorical point of view, the only reason Haskell managed to be so pure in the first place was the lazyness. If your language is not lazy its very tempting to add sideeffects.