Strumenti Utente

Strumenti Sito


magistraleinformaticanetworking:spm:ocaml-intro

Differenze

Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.

Link a questa pagina di confronto

Prossima revisione
Revisione precedente
magistraleinformaticanetworking:spm:ocaml-intro [29/03/2011 alle 18:01 (14 anni fa)] – creata Marco Daneluttomagistraleinformaticanetworking:spm:ocaml-intro [31/03/2011 alle 08:33 (14 anni fa)] (versione attuale) – [SPM resources] Marco Danelutto
Linea 3: Linea 3:
 ==== Download ===== ==== Download =====
 Ocaml may be downloaded from the INRIA official [[http://caml.inria.fr/ocaml/|Ocaml]] web page (follow Download tab). Implementation exist running on Linux, Mac OS X and Windows.  Ocaml may be downloaded from the INRIA official [[http://caml.inria.fr/ocaml/|Ocaml]] web page (follow Download tab). Implementation exist running on Linux, Mac OS X and Windows. 
 +
 +==== Documentation ==== 
 +Documentation relative to Ocaml is available through the offical [[http://caml.inria.fr/resources/index.en.html|Ocaml documentation]] web page. 
 +
 +==== Running programs ====
 +
 +=== Using the interpreter ===
 +Run **ocaml** from the shell prompt, then read the program text with a **#use "filename.ml"** 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**
 +
 +<code>
 +
 +backus:SKammello marcod$ ls
 +prova.ml skeletons.ml
 +backus:SKammello marcod$ ocaml
 +        Objective Caml version 3.11.1
 +
 +# #use "prova.ml";;
 +val add : int -> int -> int = <fun>
 +Il valore della somma e' 5
 +- : unit = ()
 +# #quit;;
 +backus:SKammello marcod$ ocamlc prova.ml
 +backus:SKammello marcod$ ls -t
 +a.out prova.cmo skeletons.ml
 +prova.cmi prova.ml
 +backus:SKammello marcod$ head -1 a.out 
 +#!/usr/local/bin/ocamlrun
 +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 prova.ml 
 +let add x y = x + y;; 
 +
 +Printf.printf "Il valore della somma e' %d\n" (add 2 3);;
 +backus:SKammello marcod$ 
 +</code>
 +==== SPM resources ====
 +Here you'll find Ocaml code related to the SPM course. 
 +
 +  - [[skelfsem|Sample skeleton set functional semantics]]  - [[http://backus.di.unipi.it/~marcod/SPM1011/dump2903.txt|terminal dump]] of the lesson given on Tue, March 29, 4pm  
 +  - float aritmetic operators are indicated with a dot after the operator symbol (this was asked during March 29 lesson): 
 +<code> 
 +# 0.0 +. 1.0 ;;
 +- : float = 1.
 +
 +</code>
 +
magistraleinformaticanetworking/spm/ocaml-intro.1301421704.txt.gz · Ultima modifica: 29/03/2011 alle 18:01 (14 anni fa) da Marco Danelutto

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki