1 Test Cases
2 OCaml’s if
3 Recursion:
4 Problems:

Assignment 1, CSC429, Spring 2009

These are some warm-up exercises, to help you get used to programming in OCAML.

1 Test Cases

You must have test cases for each function; each test case should be an expression that produces true if the test case passes, and false if it fails. Ideally, it will also print a message when a test case fails.

2 OCaml’s if

In order to complete some of the problems here, you’ll need to use OCaml’s if, which won’t be too surprising except that it requires an explicit then:

So, for instance, these two expressions:

if (3 > 4)

then 15

else 156;;

 

if true

then "abc"

else "def";;

produce these two results:

#     - : int = 156

#       - : string = "abc"

3 Recursion:

In order to make an OCaml function recursive, you must declare it with "let rec", rather than "let".

So, for instance, here’s an infinite loop (with a call to it):

let rec loop x = loop x;;

 

(loop "dontcare");;

4 Problems: