diff --git a/algo/ocaml/.list.ml.un~ b/algo/ocaml/.list.ml.un~ new file mode 100644 index 0000000..ff7c2c2 Binary files /dev/null and b/algo/ocaml/.list.ml.un~ differ diff --git a/algo/ocaml/cours.ml b/algo/ocaml/cours.ml new file mode 100644 index 0000000..f9d41df --- /dev/null +++ b/algo/ocaml/cours.ml @@ -0,0 +1,7 @@ +(*3 : construire une liste*) + +let rec f = function + 0->[] + |n -> n::f(n-1);; +(*val f:int -> int list =*) + diff --git a/algo/ocaml/list.ml b/algo/ocaml/list.ml new file mode 100644 index 0000000..2ee47ae --- /dev/null +++ b/algo/ocaml/list.ml @@ -0,0 +1,16 @@ +let i arth n a r= + if n<= 0 then + invalid_arg "invalide arg" + else + let rec suite n a = + if n=0 then + [] + else + a::suite(n-1)(a+2) + in suite n a;; + +let rec concat l l2 = + match l with + []->l2 + |e::l->e::concat l l2;; + diff --git a/algo/ocaml/liste.ml b/algo/ocaml/liste.ml new file mode 100644 index 0000000..7f01e54 --- /dev/null +++ b/algo/ocaml/liste.ml @@ -0,0 +1,15 @@ + + + + + +let rec maxprof lst = match lst with + [e] -> e + |e::l -> let m = maxprof l in if e>m then e else m + |[]->failwith "liste vide";; + +let rec max2 a l = match l with + [] -> a + |e::l -> if a < e then max2 e l else max2 a l;; +maxprof [3;2;19;4];; +