From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id C1123BC0A for ; Mon, 8 Jan 2007 03:49:30 +0100 (CET) Received: from ptb-relay03.plus.net (ptb-relay03.plus.net [212.159.14.214]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l082nURe025864 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Mon, 8 Jan 2007 03:49:30 +0100 Received: from [80.229.56.224] (helo=[10.0.0.5]) by ptb-relay03.plus.net with esmtp (Exim) id 1H3kZl-0001dn-HV for caml-list@yquem.inria.fr; Mon, 08 Jan 2007 02:49:29 +0000 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Before teaching OCaml Date: Mon, 8 Jan 2007 02:47:35 +0000 User-Agent: KMail/1.9.5 References: <1168193722.6133.38.camel@Blefuscu> In-Reply-To: <1168193722.6133.38.camel@Blefuscu> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200701080247.35509.jon@ffconsultancy.com> X-Miltered: at discorde with ID 45A1B13A.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 ocaml:01 cygwin:01 makefiles:01 emacs:01 emacs:01 syntax:01 mli:01 mll:01 syntax:01 mli:01 threads:01 fsharp:01 lablgtk:01 argv:01 On Sunday 07 January 2007 18:15, David Teller wrote: > Dear list, > > I'm going to start teaching OCaml soon and I'm fishing for ideas and > suggestions. I hope this list is the right place to ask. > > Within a few weeks, I'll be teaching OCaml to a class of second-year > students in _mathematics & informatics_. We have created quite a bit of free educational material about OCaml/F# and aimed broadly at scientists. I'm sure you'll get some inspiration from our work. > The bad part is that their > knowledge of computer science is limited to 3 term-long lectures of > "algorithmics" (read "Java under Windows"), That isn't good but mathematicians should be able to learn the basics of asymptotic algorithmic complexity in an hour. My book "OCaml for Scientists" contains an ideal mathematical explanation of this topic, using ipow and a case study and plotting the real and asymptotic complexities as well as the measured time taken. > and that they have nil > knowledge of Unix/Cygwin or Makefiles, or even Emacs or command-lines. I use Emacs under Debian linux. The syntax highlighting (of mli, ml but also mll and mly files) is great and autoindentation is indispensable for me. However, there is a bit of a learning curve here, especially if they have to install the software themselves. Also, I'm not sure how well it works under Windows. If you're using Windows then I highly recommend the related language F# and Visual Studio 2005. The IDE does color syntax highlighting for .fs and .fsi (equivalent to .ml and .mli) files. As a .NET language, you get instant access to all of the functionality provided by .NET, such as database and web connectivity. > The good part is that a number of them consider Java "not mathematical > enough", so they may be good candidates for functional programming. Excellent. There are many programs that they will probably jump at. You might like to start with a logic problem, like solving Sudoku puzzles: http://www.ffconsultancy.com/free/sudoku/ The core of the program is simply this: let rec search ?(x=0) ?(y=0) f accu = match x, y with 9, y -> search ~x:0 ~y:(y+1) f accu (* Next row *) | 0, 9 -> f accu | x, y -> if m.(y).[x] <> '0' then search ~x:(x+1) ~y f accu else fold (fun accu n -> let n = Char.chr (n + 48) in if invalid x y n then accu else (m.(y).[x] <- n; let accu = search ~x:(x+1) ~y f accu in m.(y).[x] <- '0'; accu)) accu 1 10 We've also written a GUI version in F# using Windows Forms, threads and other features: http://www.ffconsultancy.com/dotnet/fsharp/sudoku/ > I'm planning to base my lecture roughly on part 1 of _Developing > applications with Objective Caml_, If you're interested in teaching functional programming more than other aspects (e.g. interoperability) then you might also consider the freely available first chapter of my book: http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html > perhaps replacing the chapter devoted > to Graphics with the use of LablGTK. I recommend using OpenGL with OCaml/Linux or DirectX with Windows. The OpenGL examples from my book are freely available here: http://www.ffconsultancy.com/products/ocaml_for_scientists/visualisation/ The minimal demo is just this: let () = let argv' = Glut.init Sys.argv in ignore (Glut.createWindow ~title:"OpenGL Demo"); GlClear.color (0.1, 0.3, 0.1); Glut.displayFunc ~cb:(fun () -> GlClear.clear [ `color ]; Gl.flush ()); Glut.mainLoop () Here is a DirectX demo for F#: http://www.ffconsultancy.com/dotnet/fsharp/teapot/ I have just finished writing a minimal scene graph library for F# for my forthcoming book "F# for Scientists". This defines a variant type representing nested transforms, groups and primitives. When the top-level (called the F# interactive mode) sees one of these it automatically spawns a visualisation window. This is ideal for educational purposes as the students are freed from the burden of rendering contexts, device losses, double buffering and so on. > Then again, perhaps not. Some > low-level graphics might be interesting for them. Creating graphics with OpenGL and DirectX is easy enough that the immense gratification given by the result make it worthwhile. I strongly recommend using graphics on a teaching course. > I also intend to give > them a term-long project to work on and develop. As other people have suggested, some form of interpreter or compiler is ideal here. I think such a project would be greatly improved with the addition of graphics commands into the language. So a Logo, BASIC or Mathematica implementation would be ideal. Given that they are mathematicians, perhaps a mini Mathematica implementation is an ideal project? This has the interesting property of being a rewrite system (expr -> expr) rather than a conventional interpreter (expr -> value). A Mathematica implementation simply replaces input expressions according to a built-in set of rewrite rules (pattern matches). A simple Mathematica implementation can be written in well under 1,000LOC, including lexer and parser. > Right now, I see the following difficulties: > > * the environment -- under Windows, is there any viable alternative to > Emacs + the MinGW-based port ? The commercial version of Visual Studio is the only other IDE that I know of under Windows. > * the Makefile -- I've found OCamlMakefile [1] but I haven't tried it > yet, hopefully it's simple enough for my students to use without too > many arcane manipulations Make is really only useful for final, production builds in the context of OCaml. OCaml is very brittle with respect to changes but it is very fast to compile, so it is an ideal candidate for simple compilation from a bash script. > * the task -- for the moment, I have no interesting idea of OCaml-based > projects. Perhaps something like finding the shortest path along > subway/train lines ? The travelling salesman problem is one of the examples from the final chapter of my book: http://www.ffconsultancy.com/products/ocaml_for_scientists/complete/ It would be much more compelling with real-time graphics. I'll address that in my next book... We also have many other OCaml examples, including a minimal Mandelbrot renderer: http://www.ffconsultancy.com/free/fractal/ A simple ray tracer: http://www.ffconsultancy.com/free/ray_tracer/languages.html A maze generator: http://www.ffconsultancy.com/free/maze/ and so on. HTH! -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. Objective CAML for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists