type 'a t = Node of 'a * 'a t list;; Node (3, []);; let t1 = Node (3, []);; Node (2, [t1; t1; t1]);; type 'a t = Empty | Node of 'a * 'a t list;; type 'a t = Empty | Node of 'a t * 'a * 'a t;; let t1 = Empty;; let t2 = Empty;; t1 = t2;; t1 == t2;; let t1 = Node (Empty, 0, Empty);; let t2 = Node (Empty, 0, Empty);; t1 = t2;; t1 == t2;; let rec of_list = function | [] -> Empty | h :: t -> Node (Empty, h, of_list t);; of_list [3;4;5;6];; let rec split_list = function | h1 :: h2 :: t -> let (l1, l2) = split_list t in (h1 :: l1, h2 :: l2) | xs -> ([], xs);; split_list [3;4;5;6;7;7];; let rec of_list = function | [] -> Empty | l -> let (l1, h :: l2) = split_list l in Node (of_list l1, h, of_list l2);; of_list [1;2;3;4;5;6];; of_list [1;2;3;4;5;6;7];; let tt = of_list [1;2;3;4;5;6;7];; let rec size = function | Empty -> 0 | Node (l, _, r) -> size l + size r + 1;; size tt;; let rec height = function | Empty -> 0 | Node (l, _, r) -> max (height l) (height r) + 1;; height tt;; let rec insert e = function | Empty -> Node (Empty, e, Empty) | Node (l, v, r) -> if compare e v < 0 then Node (insert e l, v, r) else Node (l, v, insert e r);; List.fold_left;; List.fold_left (fun t e -> insert e t) Empty [5;4;6;5;6;5;4;8];; let bst l = List.fold_left (fun t e -> insert e t) Empty l;; let rec flatten = function | Empty -> [] | Node (l, v, r) -> (flatten l) @ (v :: (flatten r));; flatten (bst [5;76;6;4;3;4;5]);; Huffman.collate;; Huffman.collate (Strng.of_string "qwerewtrwreytretwq");; Huffman.collate (List.sort compare (Strng.of_string "qwerewtrwreytretwq"));; Huffman.tree;; Huffman.tree (Strng.of_string "qwewqerewrtwrweqwe");; let tree = Huffman.tree (Strng.of_string "qwewqerewrtwrweqwe");; Huffman.table;; Huffman.table tree;; Huffman.lookup;; let table = Huffman.table tree;; Huffman.lookup table 't';; List.map (Huffman.lookup (Huffman.table tree)) (Strng.of_string "qwewqerewrtwrweqwe");; List.concat (List.map (Huffman.lookup (Huffman.table tree)) (Strng.of_string "qwewqerewrtwrweqwe"));; List.length (List.concat (List.map (Huffman.lookup (Huffman.table tree)) (Strng.of_string "qwewqerewrtwrweqwe")));;