type complex = {re_part:float ; im_part:float};; let c1 = {re_part=1.5; im_part=0.0};; c1.re_part;; type complex = {re_part:float ; im_part:float};; fun c1 c2 -> {re_part=c1.re_part + c2.re_part ; im_part=c1.im_part +. c2.im_part};; fun c1 c2 -> {re_part=c1.re_part +. c2.re_part ; im_part=c1.im_part +. c2.im_part};; type point = {x: float; y:float};; type circle = {center: point ; radius: float};; type color = Blue | Red | Green;; Blue;; type color = Blue | Red | Green;; let f = fun c -> match c with\n Blue -> 1\n | red -> 2\n | Green -> 3;; let f = fun c -> match c with\n Blue -> 1\n | Red -> 2\n | Green -> 3;; type color = Blue | Red | Green;; let f = fun c -> match c with\n Blue -> 1\n | Red -> 2\n | Green -> 3;; type data = IntData of int | StringData of string | PairData of int*string;; let d = IntData(5);; type data = IntData of int | StringData of string | PairData of int*string;; let typeof = fun d -> match d with\n IntData(i) -> "int"\n | StringData(s) -> "string"\n | PairData(p) -> "pair";; let typeof = fun d -> match d with\n IntData(i) -> "int"\n | StringData(s) -> "string"\n | PairData(p,q) -> "pair";; type data = IntData of int | StringData of string | PairData of int*string;; let typeof = fun d -> match d with\n IntData(i) -> "int"\n | StringData(s) -> "string"\n | PairData(p,q) -> "pair";; typeof IntData(5);; typeof (IntData(5));; type inttree = Leaf of int | Node of inttree * inttree;; Node(Leaf 3, Node(Leaf 4, Leaf 5));; type 'a tree = Leaf of 'a | Node of ('a tree * 'a tree);; let rec len = fun l -> match l with\n [] -> 0\n | h::t -> 1 + len(t);; len [1;2;3;4];; let rec map = fun l f -> match l with\n [] -> []\n | h::t -> (f h)::(map t f);; map [1;2;3;4] (fun x -> x*x);; let rec append = fun l1 l2 -> match l1 with\n [] -> l2\n | h::t -> h::(append t l2);; append [1;2] [3;4];; [1;2] @ [3;4];; let rec rev = fun l -> match l with\n [] -> []\n | h::t -> t::(rev h);; let rec rev = fun l -> match l with\n [] -> []\n | h::t -> (rev t)::h;; let rec rev = fun l -> match l with\n [] -> []\n | h::t -> (rev t) @ h;; let rec rev = fun l -> match l with\n [] -> []\n | h::t -> (rev t) @ [h];; rev [1;2;3;4];; let rec rev = fun l -> match l with\n [] -> []\n | h::t -> (rev t) @ [h];; 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;3;4];; let sum = fun l -> fold_left (fun x y -> x+y) 0 l;; sum [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 rev = fun l -> fold_left (fun x y -> y::x) [] l;; rev [1;2;3;4];; List.length;; List.length [1;2;3;4];; type 'a tree = Leaf of 'a | Node of ('a tree * 'a tree);; let rec mirror = fun t -> match t with Leaf(a) -> Leaf(a) | Node(t1,t2) -> Node(mirror(t2), mirror(t1));; let rec mirror = fun t -> match t with \n Leaf(a) -> Leaf(a) | \n Node(t1,t2) -> Node(mirror(t2), mirror(t1));; type 'a tree = Leaf of 'a | Node of ('a tree * 'a tree);; let rec mirror = fun t -> match t with \n Leaf(a) -> Leaf(a) | \n Node(t1,t2) -> Node(mirror(t2), mirror(t1));; fun x -> (fun y -> (x y));; let typeof = fun d -> match d with\n IntData(i) -> "int"\n | StringData(s) -> "string"\n | PairData(p,q) -> "pair";; type data = IntData of int | StringData of string | PairData of int*string;; type color = Blue | Red | Green;; let typeof = fun d -> match d with\n IntData(i) -> "int"\n | StringData(s) -> "string"\n | PairData(p,q) -> "pair";; IntData(5);;