Laziness in Haskell — Part 1: Prologue

Laziness is a critical but often maligned aspect of Haskell, and as this video argues, it is frequently misunderstood. In this video, Alexis explains how even strict evaluation in imperative programming languages is not always quite as strict as it seems, and how deviating from strictness can often significantly improve performance.

Pipoca,

Semantically, eager languages are “strict”, while lazy languages are “non-strict”.

Strict means that f _|_ = _|_, that is to say, that passing an error value of any sort to a function must produce an error value. A lazy language is one where that isn’t a universal requirement.

So suppose we have a function like:


<span style="color:#323232;">genList 100 = error "too long"
</span><span style="color:#323232;">genList 0 = []
</span><span style="color:#323232;">genList x = x : genList (x - 1)
</span>

In a lazy language, you can have head (genList 1000) = 1000. In an eager language, it must be the case that head (genList 1000) = error “too long”, otherwise you’ve broken the semantics of the language. That requires actually evaluating the whole list.

That’s part of why laziness in strict languages has to be explicitly opt-in

  • All
  • Subscribed
  • Moderated
  • Favorites
  • haskell
  • khanakhh
  • DreamBathrooms
  • ethstaker
  • magazineikmin
  • osvaldo12
  • Durango
  • Youngstown
  • ngwrru68w68
  • slotface
  • rosin
  • mdbf
  • kavyap
  • InstantRegret
  • tester
  • JUstTest
  • thenastyranch
  • cisconetworking
  • tacticalgear
  • cubers
  • everett
  • modclub
  • GTA5RPClips
  • anitta
  • Leos
  • provamag3
  • normalnudes
  • megavids
  • lostlight
  • All magazines