User Tools

Site Tools


cs_lang:ocaml

This is an old revision of the document!


let rec pgcd a b = match (a mod b) with
  | 0 -> b
  | c -> pgcd b c;;
let rec ackermann x y = match (x,y) with
    | (0, _) -> y + 1
    | (_ , 0) -> ackermann (x - 1) 1
    | (_, _) -> ackermann (x - 1) (ackermann x (y - 1));;
let rec factorielle = function
  0 -> 1
| n -> n * factorielle (n - 1) ;;
(* Longueur d'une liste *)
# let rec longueur = function
      [] -> 0
    | t :: q -> 1 + longueur q ;;
let rec exists p = function
      [] -> false
    | a::l -> p==a || exists p l;;
cs_lang/ocaml.1310388104.txt.gz · Last modified: 2011/07/11 14:41 by cedric