Strumenti Utente

Strumenti Sito




Ocaml may be downloaded from the INRIA official Ocaml web page (follow Download tab). Implementation exist running on Linux, Mac OS X and Windows.


Documentation relative to Ocaml is available through the offical Ocaml documentation web page.

Running programs

Using the interpreter

Run ocaml from the shell prompt, then read the program text with a #use “” command. All the definitions in the file will be interpreted as if they were entered directly at the current ocaml interpreter prompt.

Compile to bytecode

Compile the program using the bytecode compiler ocamlc. Then run the resulting a.out either using ocamlrun command from the shell prompt or directly invoking the ./a.out

backus:SKammello marcod$ ls
backus:SKammello marcod$ ocaml
        Objective Caml version 3.11.1

# #use "";;
val add : int -> int -> int = <fun>
Il valore della somma e' 5
- : unit = ()
# #quit;;
backus:SKammello marcod$ ocamlc
backus:SKammello marcod$ ls -t
a.out		prova.cmo
backus:SKammello marcod$ head -1 a.out 
backus:SKammello marcod$ ./a.out
Il valore della somma e' 5
backus:SKammello marcod$ ocamlrun a.out 
Il valore della somma e' 5
backus:SKammello marcod$ cat 
let add x y = x + y;; 

Printf.printf "Il valore della somma e' %d\n" (add 2 3);;
backus:SKammello marcod$ 

SPM resources

Here you'll find Ocaml code related to the SPM course.

  1. Sample skeleton set functional semantics - terminal dump of the lesson given on Tue, March 29, 4pm
  2. float aritmetic operators are indicated with a dot after the operator symbol (this was asked during March 29 lesson):
# 0.0 +. 1.0 ;;
- : float = 1.
magistraleinformaticanetworking/spm/ocaml-intro.txt · Ultima modifica: 31/03/2011 alle 08:33 (13 anni fa) da Marco Danelutto