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.tgz
ocaml-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?
Graphics libraries aren't there (they need to be rewritten using draw(). I
don't need ocaml-x11 that bad to do it myself)
Thread libraries are not there -- both posix and non-posix threads are
missing, same as with the above lib.
Tk libraries are not compiled too, same reason.
The code is there (config/Makefile turns on the compilation) so if you're
willing...
Gotchas:
Probably many. You'll have to play with it to find out. I am
barely an ocaml user myself, so you shouldn't expect to find them
miraculously fixed in the next release (if there's any :)
This port was hard. APE's make doesn't deal well with things like $(BLAH:.a=.b),
which required an edit of almost every Makefile. Long filenames, messy
compilations and even bugs in their #ifdef-sprinkled code took about three
work days to catch. Not nice at all.
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:
The code is non-portable. the endianness is defined in config/m.h; unless
the plan9 compilers can handle that fact you won't be able to run ocaml on
a different architecture. (If I'm wrong please tell me!)
Having to run "lnfs /sys/man/man1"!!!
The installation process puts way too many binaries in /386/bin. There
should be an easier way to switch between /$objtype/[bin|lib] and
$home/[bin|lib]
You will need to run:
lnfs ocamldoc
lnfs /sys/man/man1
due to the fact that three of the ocaml web pages have long filenames. The
best way to deal with this is to have a Venti/Fossil system underneath.
Most bugs would require that you go there and solve them
yourselves. This port does not attempt to bring a full environment for
ocaml lovers, rather it just solves a request somebody posted on the
TODO page of the Plan 9 Wiki.
TODO:
plan9-native ui libs;
Tk libs;
threads
assembly optimizations (well, maybe not)
completely native port? wouldn't be easy.
Last Modified: June 19, 2007
mirtchovski at gmail