Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Computer Aided Database Design

Authors: Antonio Albano, Valeria De Antonellis, A. Di Leva

1st Edition

0444877355, 978-0444877352

More Books

Students also viewed these Databases questions