Version française
Home     About     Download     Resources     Contact us    
Browse thread
Which syntax to teach ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Andrej Bauer <Andrej.Bauer@f...>
Subject: Re: [Caml-list] Which syntax to teach ?
David Teller wrote:
>  In a few months, I'll start teaching OCaml for the second consecutive
> year. I'll solve a number of my problems by installing Linux on the
> workstations, although I'm pretty sure that will cause no end of
> complaints from the students when they need to continue their work at
> home.

My experience with teaching theory of programming languages, where we
implement mini interpreters and compilers with Ocaml:

1. Students want to use Microsoft Windows.
2. Students HATE Emacs because its basic behavior regarding selections,
   cut & paste is counter-intuitive to them.
3. Students think Make is an archaic nuisance (and they're right).

So this year we switched to Eclipse + OcaIDE + ocamlbuild. As long as
you instruct your students to install (in this order!)

  Cygwin
  Ocaml 3.10 (not from cygwin package manager!)
  Java 1.6
  Eclipse 3.2
  OcaIDE

on their home computers, they should be fine. This year students have
much less initial trouble. (The combination cygwin + XEmacs + tuareg +
ocaml + Make was a real nightmare in previous years.)

Even though OcaIDE is sort of half-done and ocamlbuild is very
Unix-centric, it's still a useful combination.

As far as teaching ocaml goes, here are a few tips:

1. Do not bore them with syntax. They will just absorb it, and it
doesn't matter which version it is, so pick the one that does not
require extra options and settings. There are a few traps they will fall
into--when they do, explain what is going on. With time you will be able
to anticipate them.

2. Point out differences with programming languages they know, e.g.:
- you can put if-then-else _anywhere_
- you can put local definitions _anywhere_
- "let x = .. in .." defines an _immutable_ value x
- functions don't have a "return" statement, you just write the result,
like you do in math

3. The following is confusing to beginners:

let f x = function <cases>

They think it's a function of one variable. When asked to define a
function of two variables, they might write

let g x y = function <cases>

So I always start strictly with the form

let f x =
  match x with
   <cases>

let g x y =
  match y with
   <cases>

Then I teach "shorthands"

let f = function ...

let g x = function ...

4. You will be sorry if they know Java and you teach them early about
references, assignments and loops.

5. Explain ahead of time why things like

   List.nth lst (List.length lst - 1)

are bad. From Java they know it's trivial to access the n-th component
and to find out the size of a container.

6. Special care is needed in explaining and advertising sum types
(variants) because they only exist in mutilated form in commonly used
languages.

7. They easily understand how the standard library is used (but not the
functors), the open statement, the fact that a program may be in several
.ml files. The .mli files are a bit more mysterious. Functors are _very_
mysterious.

8. Error messages come from hell. They are a big hurdle and you need to
devote special attention to them.

Best regards,

Andrej