OCaml Course in Ochanomizu University

(Presented at the ``Tips and Tricks'' session of FDPE'05)

Kenichi Asai

Department of Information Science, Ochanomizu University
2-1-1 Otsuka Bunkyo-ku Tokyo 112-8610 Japan
http://pllab.is.ocha.ac.jp/~asai

September 25, 2005

1  Background

Ochanomizu University is a women's university. This means that the students tend to be diligent in general, but not ambitious. 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:
  1. basic data types, variable and function definition,
  2. conditional, design recipe,
  3. tuple, record, pattern matching,
  4. list and recursion,
  5. Dijkstra's algorithm,
  6. polymorphism, map, functions without names,
  7. generative recursion, termination,
  8. accumulator,
  9. tree,
  10. balanced tree, refactoring of programs,
  11. exception handling, modules,
  12. sequential execution, arrays,
  13. mutation,
  14. heap
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.

3  Tips

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:
  1. (basics)
  2. (basics)
  3. represent station information as a record,
  4. use linear search to translate a station name in alphabet into a name in Kanji,
  5. represent graph information of the metro network,
  6. construct an initial graph for Dijkstra's algorithm from a list of station names,
  7. generate subproblems of Dijkstra's algorithm,
  8. complete the first version of the metro network problem (but it's too slow for a large data),
  9. replace linear search in the main loop with tree search,
  10. refactor parts of the program,
  11. raise exception when the input station name is not found,
  12. output the result in a nice form using a sequence of print_string, make the program stand alone and accept station names from the array for the command line arguments,
  13. compare the execution time for various implementation,
  14. extend the program in an arbitrary way students like
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.

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 audience, too. 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 HEVEA.