cs_lang:ocaml
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| cs_lang:ocaml [2011/07/12 09:57] – cedric | cs_lang:ocaml [2012/04/29 11:44] (current) – cedric | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | ====== |
| + | ===== Paradigm ==== | ||
| + | * multi-paradigm: | ||
| + | ===== Typing discipline ===== | ||
| + | * static typed; | ||
| + | * strongly typed; | ||
| + | * inferred. | ||
| + | |||
| + | |||
| + | ====== Learning Objective Caml ====== | ||
| * [[http:// | * [[http:// | ||
| - | * [[http:// | + | * [[http:// |
| ====== Simple examples ====== | ====== Simple examples ====== | ||
| + | ===== Increment a number ===== | ||
| + | <code ocaml> | ||
| + | # let inc n = n+1;; | ||
| + | val inc : int -> int = <fun> | ||
| + | |||
| + | # inc 2;; | ||
| + | - : int = 3 | ||
| + | |||
| + | |||
| + | # Alternative: | ||
| + | # let inc = (+) 1;; | ||
| + | val inc : int -> int = <fun> | ||
| + | </ | ||
| + | |||
| + | ==== Equivalent in Python ==== | ||
| + | <code python> | ||
| + | >>> | ||
| + | ... | ||
| + | |||
| + | >>> | ||
| + | 3 | ||
| + | </ | ||
| + | |||
| ===== Great common divisor ===== | ===== Great common divisor ===== | ||
| <code ocaml> | <code ocaml> | ||
| Line 28: | Line 60: | ||
| let rec parity = function | let rec parity = function | ||
| | [] -> [] | | [] -> [] | ||
| - | | x::t -> (x mod 2 == 0)::(func t);; | + | | x::l -> (x mod 2 == 0)::(parity l);; |
| val func : int list -> bool list = <fun> | val func : int list -> bool list = <fun> | ||
cs_lang/ocaml.1310457451.txt.gz · Last modified: by cedric
