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
    link
    21 year ago

    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:

    genList 100 = error "too long"
    genList 0 = []
    genList x = x : genList (x - 1)
    

    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