Question
This exercise is about carrying out lazy evaluation and noticing its pros and cons. First we need to agree on some code: mysum [] =
This exercise is about carrying out lazy evaluation and noticing its pros and cons.
First we need to agree on some code:
mysum [] = 0 mysum (x:xt) = x + mysum xt
myor [] = False myor (x:xt) = x || myor xt
"||" is implemented as:
False || c = c True || _ = True
Exercise 1 [3 marks] ----------
Show the lazy evaluation steps of
mysum (1 : 2 : 3 : [])
until you obtain a single number. It is best to add clarifying parentheses: If you have "foo + bar + quux" it is best to write either "(foo + bar) + quux" or "foo + (bar + quux)" to indicate which one you mean.
Exercise 2 [3 marks] ----------
Show the lazy evaluation steps of
myor (True : False : True : [])
until you obtain a single boolean.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started