type 'a t = Empty | Node of ('a t * 'a * 'a t);; Empty;; Node (Empty, 3, Empty);; let t1 = Node (Empty, 3, Empty);; Node (t1, 5, t1);; let of_list = List.fold_left (fun t e -> Node (Empty, e, t)) Empty;; of_list [3;65;4;7;5;8;3];; let rec split_list = function h1 :: h2 :: t -> let (l1, l2) = split_list t in (h1 :: l1, h2 :: l2) | l -> ([], l);; split_list [2;3;45;6;5;3;4;5];; split_list [2;3;45;6;5;3;4;5;7];; let of_list = function [] -> Empty | [e] -> Node (Empty, e, Empty) | l -> let (l1, h :: l2) = split_list in Node (of_list l1, h, of_list l2);; let rec of_list = function [] -> Empty | [e] -> Node (Empty, e, Empty) | l -> let (l1, h :: l2) = split_list l in Node (of_list l1, h, of_list l2);; of_list [3;4;5;6;7;6;4;3;2;3;4];; 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);; let insert t e = insert e t;; List.fold_left;; List.fold_left insert;; List.fold_left insert Empty;; let bst = List.fold_left insert Empty;; bst [3;65;4;6;4;5;2;7];; let rec flatten = function Empty -> [] | Node (l, v, r) -> flatten l @ (v :: flatten r);; flatten (bst [3;65;4;6;4;5;2;7]);; module L = List;; module B = BinTree;; B.of_list [4;6;5;7;8];; B.make [4;6;5;7;8;9;12];; Huffman.collate ['e';'t';'x';'t'];; Huffman.collate ['e';'t';'t';'x'];; let tree = Huffman.tree "text";; let tree = Huffman.tree (Strng.of_string "text");; Huffman.toplevel_printer;; #install_printer Huffman.toplevel_printer;; let tree = Huffman.tree (Strng.of_string "text");; Huffman.lookup;; Huffman.lookup tree;; Huffman.lookup (Huffman.table tree);; Huffman.lookup (Huffman.table tree) 't';; Huffman.lookup (Huffman.table tree) 'e';; List.map (Huffman.lookup (Huffman.table tree)) [Strng.of_string "text"];; List.map (Huffman.lookup (Huffman.table tree)) (Strng.of_string "text");; List.concat (List.map (Huffman.lookup (Huffman.table tree)) (Strng.of_string "text"));;