Exercises for Week 05

Exercise 0

  1. At the top right and at the bottom right of the present page, there is a clickable word, “index”, to access the index of the current version of the lecture notes. Click on it and then peruse the index, making sure that its entries make sense to you (otherwise, click on them to check them out).
  2. The lecture notes start with updates (Chapter Lecture Notes for Intro to CS, updates). Make sure to check them out regularly, as they reflect the development of the lecture.
  3. Make sure to reflect on Exercise 19 in Week 04.
  4. Do take the time to peruse the lecture notes of this week and to reproduce their OCaml content.

Mandatory exercises

  • Exercise 0: perusing the index and checking the updates
  • Exercise 1: some food for thought about basic computational arithmetic
  • Exercise 2: mapping a string of letters from lowercase to uppercase and vice-versa
  • Exercise 6: implementing a polymorphic unparser for quadruples
  • Exercise 11: debugging an implementation of the power function

Exercise 11

The accompanying file contains a bug, and your task is to fix this bug.

To this end, load this file a few times in OCaml, as in:

# #use "week-05_power.ml";;
...
#

until the bug becomes apparent (i.e., when an assertion fails to hold).

Then figure it out and fix it.

Hint: redefine the silent flag at the beginning of the file to enable the displaying of error messages.

Subsidiary request: analyze the said error messages, their structure, and how they come about.

Resources

  • The OCaml code for Exercise 11 (latest version: 13 Feb 2021).

Version

Fixed a typo, thanks to Ann Chen’s ever-vigilant eagle eye [17 Feb 2021]

Wordsmithed the statement of Exercise 11 [13 Feb 2021]

Created [13 Feb 2021]

Table Of Contents

Previous topic

Induction and recursion over natural numbers

Next topic

Lecture Notes, Week 06