Ocaml for Plan 9
NEWS: updated to 3.10.0 with a lot of effort
See Readme file.What is this?
This is a port of the Ocaml (Caml is the language, Ocaml is "Objective Caml") functional (and more) programming language to the Plan 9 from Bell Labs Operating System. To get more information about Ocaml go to caml.inria.fr.
If you want ocaml examples download them from: oc.tar.gz.
Warning -- not all examples would compile!
Download:
ocaml-plan9-3.10.tgzocaml-plan9-3.06.tgz
Examples:
Here is a taste of some of the examples and the ocaml interpreter:
3.10: Interpreter: parr% ocaml Objective Caml version 3.10.0 # 3*4;; - : int = 12 # print_string "Hello World\n";; Hello World - : unit = () # let rec fibonacci x = match x with 0 -> 1 | 1 -> 1 | n -> fibonacci (x - 1) + fibonacci (x - 2);; val fibonacci : int -> int =# fibonacci 10;; - : int = 89 # The bytecode compiler that allows you to create ocaml "binaries" which ocamlrun can interpret parr% cat hello.ml print_string "Hello world!\n";; parr% ocamlc hello.ml -o hello parr% ./hello Hello world! parr%
cpu% ape/psh $ make ocamlc -g -c hello.ml ocamlc hello.cmo -o hello ocamlc -g -c greeting.ml ocamlc greeting.cmo -o greeting ocamlc -g -c argcargv.ml ocamlc argcargv.cmo -o argcargv [snip] $ ./hello Hello world! $ cat wc_unix.ml | ./wc 2761 characters, 367 words, 86 lines $ queens Chess boards's size ? 5 The 5 queens problem has 10 solutions. Do you want to see the solutions? y Solution number 1 - - - Q - - Q - - - - - - - Q - - Q - - Q - - - - Solution number 2 - - Q - - - - - - Q - Q - - - - - - Q - Q - - - - Solution number 3 - - - - Q - - Q - - Q - - - - - - - Q - - Q - - - Solution number 4 - - - Q - Q - - - - - - Q - - - - - - Q - Q - - - Solution number 5 - - - - Q - Q - - - - - - Q - Q - - - - - - Q - - Solution number 6 Q - - - - - - - Q - - Q - - - - - - - Q - - Q - - Solution number 7 - Q - - - - - - - Q - - Q - - Q - - - - - - - Q - Solution number 8 Q - - - - - - Q - - - - - - Q - Q - - - - - - Q - Solution number 9 - - Q - - Q - - - - - - - Q - - Q - - - - - - - Q Solution number 10 - Q - - - - - - Q - Q - - - - - - Q - - - - - - Q $ Examples of the ocaml interpreter: cpu% ocaml Objective Caml version 3.06 # let square (x) = x * x;; val square : int -> int = # let rec fact (x) = if x <= 1 then 1 else x * fact (x-1);; val fact : int -> int = # fact(5) ;; - : int = 120 # square(5);; - : int = 25 # square(fact(2));; - : int = 4 #
What's there?
This port uses the APE environment, i.e. it is not native. All of the unix functionality that ocaml needs and APE supports is there. The interpreter seems to run but is not thoroughly tested (I am not very fluent in Caml).
What's missing?
Gotchas:
Compile instructions:
gunzip < ocaml-plan9-3.06.tgz | tar xv cd ocaml-3.06/ lnfs ocamldoc # if you don't use fossil lnfs /sys/man/man1 # if you don't use fossil ape/psh make world make install
BUGS:
TODO:
Last Modified: June 19, 2007
mirtchovski at gmail