Ocaml track: assignment 1: warmups


Goals

In this assignment you will learn the basics of ocaml by writing a lot of simple functions.

Language concepts covered this week

Reading

Read chapters 1 to 6 in the textbook. This is a fair amount of reading, but once it's done you'll understand the most basic parts of the ocaml language. Consider this to be the main part of your homework for week 1.

Program to write

For this week, you will be solving a number of simple problems by writing a bunch of simple functions in a file called warmups.ml. Write these functions in a pure functional style only: no assignment statements, no explicit loops, and no arrays!

Here are the problems you have to solve:

To hand in

The file warmups.ml.

Supporting files

None this week. Instead just use the top-level ocaml interpreter. While in the interpreter type

# #use "warmups.ml";;

to compile your code (the first "#" is the ocaml prompt). Ocaml will also print out the type signatures of your functions, which you may find useful. Once this is done you can test your functions. In later labs I'll be supplying code which will test your functions non-interactively.

Note that your code must not generate any compiler warnings.

References