Exercises for Week 08

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. Time permitting, do peruse the lecture notes of this week, reproducing their OCaml content.

Mandatory exercises

Due to the midterm project, these exercises are delayed until Week 09.

  • Exercise 1: implementing list predicates
  • Exercise 6: unzipping a list of pairs into a pair of lists
  • Exercise 8: implementing the list analogue of String.mapi

Exercise 23

Implement the logical counterparts of String.map, string_andmap and string_ormap, so that:

  • string_andmap p "abc" corresponds to p 'a' && p 'b' && p 'c' && true, and
  • string_ormap p "abc" corresponds to p 'a' || p 'b' || p 'c' || false.

Exercise 24

Implement the logical counterparts of String.mapi, string_andmapi and string_ormapi, so that:

  • string_andmapi p "abc" corresponds to p 0 'a' && p 1 'b' && p 2 'c' && true, and
  • string_ormapi p "abc" corresponds to p 0 'a' || p 1 'b' || p 2 'c' || false.
Harald: I think that we could use string_andmapi...
Alfrothul: ...to test whether a string is a palindrome.
Loki: Good thinking, guys. Good thinking.

Version

Added Exercises 23 and 24 [24 Mar 2021]

Finalized [21 Mar 2021]

Created [14 Mar 2021]

Table Of Contents

Previous topic

Representing sets as lists

Next topic

Lecture Notes, Week 09