let a=5;; let a=5\nfdsafdsa;; let rec iter = fun n f x -> match n with\n | 0 -> x\n | n -> f (iter (n - 1) f x);; iter 3 (fun x -> x+x) 2;; let rec loop = fun p f x -> if (p x) then x else (loop p f (f x));; iter 3 (fun x -> x+x) 2;; let rec loop = fun p f x -> if (p x) then x else (loop p f (f x));; let rec iter = fun n f x -> match n with | 0 -> x | n -> f (iter (n - 1) f x);; loop (fun x -> x=2) (fun x -> x) 1;; let rec loop = fun p f x -> if (p x) then x else (loop p f (f x));; loop (fun x -> false) (fun x -> x) 1;; let rec iter = fun n f x -> match n with | 0 -> x | n -> f (iter (n - 1) f x);; iter (- 1) (fun x->x) 2;; let rec iter = fun n f x -> match n with | 0 -> x | n -> f (iter (n - 1) f x);; type complex = {re_part : float; im_part: float};; let cx1 = {re_part=1.0; im_part=0.0};; cx1.re_part;; type circle = {center: complex; radius: float};; type color = Blue | Red | Green;; Blue;; type color = Blue | Red | Green;; let c = Orange;; type data = IntData of int | StringData of string | PairData of int*string;; let d = IntData(5);; let e = PairData(5,"a");; let typeof = fun d -> match d with \n | IntData(i) -> "int"\n | StringData(s) -> "string"\n | PairData(p1,p2) -> "pair";; typeof (IntData 5);; type inttree = Leaf of int | Node of inttree 8 inttree;; type inttree = Leaf of int | Node of inttree * inttree;; Leaf(3);; Node(Leaf 3, Node (Leaf 4), (Leaf 5) );; Node(Leaf 3, (Node (Leaf 4), (Leaf 5) ));; Node(Leaf 3, (Node (Leaf 4), (Leaf 5) )));; Node( (Leaf 3), (Leaf 4));; Node( (Leaf 3), Node(Leaf(4), Leaf(5)));; 5;; 3+5;; Node( (Leaf 3), Node(Leaf(4), Leaf(5)));; let rec sum = fun t -> match t with \n Leaf(n) -> n \n | Node(n1, n2) -> sum(n1) + sum(n2);; sum(Node( (Leaf 3), Node(Leaf(4), Leaf(5))));; Node( (Leaf 3), Node(Leaf(4), Leaf(5)));; type data = IntData of int | StringData of string | PairData of int*string;; IntDate(5);; IntData(5);; type 'a tree = Leaf of 'a | Node of ('a tree) * ('a tree) ;; Node(Leaf(3), Node(Leaf(4), Leaf(5)));; Node(Leaf("3"), Node(Leaf("4"), Leaf("5")));; type 'a linkedlist = Nil | Cons of 'a * ('a list);; Cons(3, Nil);; type 'a linkedlist = Nil | Cons of 'a * ('a linkedlist);; Cons(3, Nil);; Cons(3, Cons(4, Cons(5, Cons(6, Nil))));; [];; [3];; 3::[];; 3::(4::[]);; let rec len = fun l -> match l with\n | [] -> 0\n | h::t -> 1 + len(t);; len [1;2;3;50];; let rec map = fun l f -> match l with\n | [] -> []\n | h::t -> f(h)::(map t f);; map [1;2;3] (fun x -> x*x);; let rec append = fun l r -> match l with \n | [] -> r\n | h::t -> h::(append t r);; append [1;2] [3;4];; [1;2] @ [3;4];; let rec append = fun l r -> match l with \n | [] -> r\n | x::y -> x::(append y r);; append [1;2] [3;4];; let rec rev = fun l -> match l with\n | [] -> []\n | h::t -> append (rev t) h;; let rec rev = fun l -> match l with\n | [] -> []\n | h::t -> append (rev t) [h];; append [1;2;3;4];; rev [1;2;3;4];; let rec fold_left = fun f accu l -> match l with\n | [] -> accu\n | h::t -> fold_left f (f accu h) t;; let len = fun l -> fold_left (fun x y -> x+1) 0 l;; len [1;2];; let rev = fun l -> fold_left (fun x y -> y::x) [] l;; rev [1;2;3];; let rev = fun l -> fold_left (fun x y -> y::x) [] l;; let rec fold_left = fun f accu l -> match l with\n | [] -> accu\n | h::t -> fold_left f (f accu h) t;; let rev = fun l -> fold_left (fun x y -> y::x) [] l;; rev [1;2];; let rec fold_left = fun f accu l -> match l with\n | [] -> accu\n | h::t -> fold_left f (f accu h) t;; let rev = fun l -> fold_left (fun x y -> y::x) [] l;; let len = fun l -> fold_left (fun x y -> x+1) 0 l;; let rec fold_left = fun f accu l -> match l with\n | [] -> accu\n | h::t -> fold_left f (f accu h) t;; let rev = fun l -> fold_left (fun x y -> y::x) [] l;;