Course Links

Resources

External

This lab will give you practice with debugging OCaml programs. The lab consists of three versions of an OCaml program, each with a different category of errors. As practice for debugging your own programs, you can work through these examples. To make it easier, the location of each error is provided below in hidden form. Only use the hints if you absolutely need them.

Types of Errors

Programming errors may be broadly categorized into three types, described below. The lab includes one practice file for each category.

Syntax Errors
Instances where a program does not obey the rules of OCaml syntax will be detected by the compiler, and reported as errors. This is actually a service provided by the compiler, because such mistakes can be caught early during development rather than later on after the program is deployed and running. With practice, every programmer should eventually be able to eliminate syntax errors to produce code that compiles cleanly. Unfortunately, the OCaml compiler is not always very good at localizing the source of a problem. Often the line where it realizes that a syntax error must exist, and therefore the location that is reported for the error, is not actually the line where the mistake was made. A great example of this is a missing quotation mark, which will not be detected until the end of the file is reached and the unpaired quote mark is discovered.
Runtime Errors
Runtime errors are the second easiest type of error to detect and fix. By definition they are not discovered during compilation. Rather, they are discovered and reported as the program is running, often causing the failure of whatever piece of code was in progress. A classic example of a runtime error is division by zero: the compiler cannot predict it, but when it happens the program cannot complete the desired division.
Logic Error
A logic error is a mistake in thinking about how a program should work in order to solve the desired task. Programs with logic errors will run to completion, but will not (always) produce the correct result. This sort of error can be detected by thorough testing during development.

To Do

Download the files from Moodle at this link. This should give you a zip archive containing four files: assert.ml, syntax.ml, runtime.ml, and logic.ml. As in the previous lab, you will not modify assert.ml. Each of the other files contains practice examples of the corresponding error type.

Try to fix the programs on your own as practice. To help you in case you get stuck, the links that follow will reveal the line numbers of each of the errors present in the file. Use them only if necessary.

Syntax errors: #1, #2, #3, #4, #5, #6, #7, #8, #9, #10, #11

Runtime errors: #1, #2, #3

Logic errors: #1, #2, #3