OCaml Course in Ochanomizu University
(Presented at the ``Tips and Tricks'' session of
Department of Information Science,
2-1-1 Otsuka Bunkyo-ku Tokyo 112-8610 Japan
September 25, 2005
Ochanomizu University is a women's university.
This means that the students tend to be diligent in general, but not
They do what they are told to do, but not more than that, to pursue
their own interest for example.
It is important to motivate them well, so that they feel they want to
do more than simple exercises.
2 The OCaml Course
The course is mainly for the second year undergraduate students.
In their first year, students learn C (sigh).
This means that they know how to use editors, what programming in
general is, how to write small programs like quick sort in C, but
nothing about functional languages.
I chose the second year because I do not have to teach editors, yet
students are not fully addicted to imperative languages.
The course is held once a week from mid-April to the end of July
(around 14 weeks).
One course is 90 minutes long, but I usually do not use whole the 90
minutes, but use only about 60 minutes and students do the exercises
by themselves after the class or whenever they want.
The course is held in a standard class room, not a computer room.
Syllabus of the course is:
The goal of the course is threefold: students acquire OCaml language
itself, students learn how to write programs in general, and students
experience construction of somewhat bigger programs than quick sort.
basic data types, variable and function definition,
- conditional, design recipe,
- tuple, record, pattern matching,
- list and recursion,
- Dijkstra's algorithm,
- polymorphism, map, functions without names,
- generative recursion, termination,
- balanced tree, refactoring of programs,
- exception handling, modules,
- sequential execution, arrays,
Show the goal
- To attract students and help maintain their
motivation, I first declare that the students will solve ``the
shortest path problem for the metro subway network in Tokyo."
The above syllabus is carefully designed so that each class is
something to do with this problem (except for the first two classes,
which are too basic).
Here goes the syllabus from this point of view:
Showing a non-trivial goal at the beginning of the course helps
to maintain the motivation of students greatly.
Not a small number of students told me after the course that they did
not think at first that they could ever make such a program at all and
when they could, they were very happy.
- represent station information as a record,
- use linear search to translate a station name in alphabet into a
name in Kanji,
- represent graph information of the metro network,
- construct an initial graph for Dijkstra's algorithm from a list
of station names,
- generate subproblems of Dijkstra's algorithm,
- complete the first version of the metro network problem (but
it's too slow for a large data),
- replace linear search in the main loop with tree search,
- refactor parts of the program,
- raise exception when the input station name is not found,
- output the result in a nice form using a sequence of
_string, make the program stand alone and accept station
names from the array for the command line arguments,
- compare the execution time for various implementation,
- extend the program in an arbitrary way students like
- Use Design Recipe
The use of Design Recipe (introduced in
HTDP) is effective to teach
not only Scheme but also a typed language like OCaml.
With Design Recipe, students realize that programming is not a
random process but a disciplined activity.
The use of Design Recipe makes the course understandable to wider
Although the course is mainly for the computer science department,
a student from French literature took the course this year,
who had almost no programming experience before.
Yet, she could complete the shortest path problem (with my help) and
is now trying to revise it using trees.
She described Design Recipe as the sole mental prop she can rely on.
This document was translated from LATEX by