Re:Introduction to Functional Programming in OCaml
by arunix on Thursday August 23, 2018 @12:55PM
(#17828763)
Why does laziness hinder reasoning and predictability?
[ Parent
| on HN ]
Re:Introduction to Functional Programming in OCaml
by atombender on Thursday August 23, 2018 @06:03PM
(#17831028)
Laziness disassociates the execution of a function from its call site. A classic novice mistake is to accidentally read a file after closing it -- something that can happen even if the "read" function is called before the "close" function in the code. It happens because the read function isn't actually called until its return value is used, and that can very well happen after the close call.
So you have an implicit dependency graph of evaluation that doesn't exactly match the chain of function call. You may find that some slow code gets deferred until in the middle of some time-sensitive code, for example. You could also have something blow up that's completely unrelated to the calling code, again because of the laziness.
The opposite of lazy is strict, and Haskell does let you "opt in" to strictness when you require it.
Re:Introduction to Functional Programming in OCaml
by n42 on Thursday August 23, 2018 @06:14PM
(#17831093)
Check out Purely Functional Data Structures by Chris Okasaki: https://www.cs.cmu.edu/~rwh/theses/okasaki.pdf