Lazy evaluation Flashcards
How are expressions in Haskell evaluated?
Lazy evaluation
What are the benefits of lazy evaluation?
- Avoids doing unnecessary evaluation
- Ensures termination whenever possible
- Supports programming with infinite lists
- Allows programs to be more modular (separates control and data)
If the program terminates, what can we say about the ways of evaluating the same expression?
Anyway of evaluating the same expression will give the same result provided it terminates
What is a redex?
A reducible expression
What are the two main evaluation strategies?
- Choose a redex that is innermost (doesn’t contain another redex)
- Choose a redex that is outermost (is not contained in another redex)
Compare termination with innermost and outermost evaluation
Outermost evaluation may give a result when innermost evaluation fails to terminate
If any evaluation sequence terminates, then so does the outermost, with the same result
Compare the number of reduction steps with innermost and outermost evaluation
Outermost evaluation may require more steps than innermost
How do we reduce the number of steps in outermost evaluation?
Using pointers to indicate sharing of arguments
What is lazy evaluation?
Lazy evaluation = outermost evaluation + sharing of arguments
What does Lazy Evaluation ensure?
Termination whenever possible, it never requires more steps then innermost evaluation
What is modular programming?
Seperating control from data
LE allows this