(* This code extends 'mini_prelude'. *) datatype ('a) heap = Tree of 'a * (('a) heap) list | Empty ; val empty = Empty ; val is_empty = (fn v3 => (case v3 of Empty => true | (Tree (v2, v1)) => false)) ; val merge = (fn v8 => (fn v9 => (fn v10 => (fn v7 => (case v10 of Empty => (case v7 of Empty => Empty | (Tree (v2, v1)) => (Tree (v2, v1))) | (Tree (v6, v5)) => (case v7 of Empty => (Tree (v6, v5)) | (Tree (v4, v3)) => (if ((v9 (v8 v6)) (v8 v4)) then (Tree (v6, (Cons ((Tree (v4, v3)), v5)))) else (Tree (v4, (Cons ((Tree (v6, v5)), v3))))))))))) ; val insert = (fn v1 => (fn v3 => (fn v4 => (fn v2 => ((((merge v1) v3) (Tree (v4, Nil))) v2))))) ; fun merge_pairs v5 = (fn v6 => (fn v7 => (case v7 of Nil => Empty | (Cons (v4, v3)) => (case v3 of Nil => v4 | (Cons (v2, v1)) => ((((merge v5) v6) ((((merge v5) v6) v4) v2)) (((merge_pairs v5) v6) v1)))))) ; val find_min = (fn x1 => (case x1 of Empty => (raise Bind) | (Tree (v2, v1)) => v2)) ; val delete_min = (fn x1 => (fn x2 => (fn x3 => (case x3 of Empty => (raise Bind) | (Tree (v2, v1)) => (((merge_pairs x1) x2) v1))))) ;