OCaml for teaching?
I’ve been thinking lately: What would happen if we used OCaml as a language for introductory programming at the collegiate level?
To be sure, it would need some improvement to be suitable for this. For starters, a compiler with more useful error messages (although I have heard that using camlp4 improves error message quality). Also, some good interactive environment, possibly fusing the capabilities of DrScheme and Eclipse, would be most beneficial (I have heard of the existence of a project called DrOcaml; perhaps it has some merit).
But using OCaml would, I believe, have some good and interesting implications. It would preserve the functional beginnings that are gained in programs teaching Scheme as a first language — you work with recursion, have a tail-recursive system, etc. Further, it’s strongly typed, so you avoid a whole class of errors that arise in Scheme.
It would also be applicable to the second term data structures teaching. With its object system, students can be taught object-oriented principles (albeit in a somewhat different style than that employed by Java et. al.). You can do the data structures work — lists, trees, queues, stacks, etc. in it. Imperative features (references, mutable record fields, mutable instance variables, etc.) are available, and I/O is done in a somewhat imperative fashion, so many data-structures things can be done, and imperative basics can be introduced (in a highly structured manner).
OCaml certainly isn’t the perfect language for programming education. No language is (well, Pascal might have been, but that’s debatable). But I think we could see some interesting results come of it. And we would, perhaps, produce programmers that are more strongly discontent with the meager offerings of the "common" languages.
Comment from Massimiliano on May 16, 2008 at 11:00 AM CDT
During higher school I was introduced to Pascal, but the first language I was thought at University was indeed OCaml (actually not the OO part but the functional core) and I really enjoyed it. OCaml is still my favourite language.