3 ms·
Laziness is pretty implicit and while it enables all kinds of optimizations and reasoning it can be hard to understand the sequencing of effects. In particular,
by tel 13y ago
Laziness is pretty implicit and while it enables all kinds of optimizations and reasoning it can be hard to understand the sequencing of effects. In particular, laziness and IO lead to code where handle opening and closure is difficult to understand. For instance
lines :: IO [String]
lines = withFile path $ \h -> hReadLines h
will generate a lazy stream of strings in an IO action without actually reading those lines. You can either close the handle immediately and get a runtime error later when you force those lines OR leave it open and leak a file handle.
Explicit coroutines help to ensure that you know exactly what to expect from effect interleaving.
Mario Blazevic's article [0] is the quintessential treatment and forms the basis of the Pipes library today.
[0] http://themonadreader.files.wordpress.com/2011/10/issue19.pdf http://themonadreader.files.wordpress.com/2011/10/issue19.pd...