Course Links

Resources

External

This lab will give you practice working with OCaml. As before, it is designed with instructions and examples contained within comments in the file you will be editing. The lab will walk you through several stategies for debugging OCaml programs.

Debugging Strategies

Manual Analysis
Manual analysis of code is a form of close reading, looking at the program and mentally breaking it down into component parts to confirm that each part does what you intend. In OCaml, one way to do this is to simulate the execution (simplification) of a test expression. We have seen some examples of this in the lectures -- now is your chance to try it for yourself. Done carefully, manual analysis can be one of the most effective debugging tools available to you.
Thorough Testing
Well-chosen tests can help to reveal the nature of a bug. If you have a battery of tests that thoroughly cover all possible code branches, then the failure of one or more tests should lead you directly to the part of your program that has the problem. (Keep in mind that a newly written test may itself have a bug in it, so you should always double-check this if you can't find the problem within the function you are testing.)
Using Printouts
Often it is useful to know not just that a piece of code has executed incorrectly, but exactly how it has done so. Adding statements to print out key values can be a very important tool for debugging. Often seeing the incorrect value produced by a function can tell you exactly what went wrong.

To Do

Download the files from Moodle at this link. This should give you a zip archive containing two files: assert.ml and debugging.ml. As in the previous lab, you will not modify assert.ml -- all of your work is contained within debugging.ml.

Open debugging.ml in a program editor. Read the comments, look at the examples, and follow the instructions therein. An answer key will be posted following the lab session.