(* This code extends 'mini_prelude'. *) type ('a) queue = Queue of ('a) list * int * ('a) list * int * ('a) list ;; let empty = (Queue (Nil, 0, Nil, 0, Nil)) ;; let is_empty = (fun v6 -> (match v6 with (Queue (v5, v4, v3, v2, v1)) -> (v4 <= 0))) ;; let checkw = (fun v8 -> (match v8 with (Queue (v7, v6, v5, v4, v3)) -> (match v7 with Nil -> (Queue (v5, v6, v5, v4, v3)) | (Cons (v2, v1)) -> (Queue ((Cons (v2, v1)), v6, v5, v4, v3))))) ;; let check = (fun v6 -> (match v6 with (Queue (v5, v4, v3, v2, v1)) -> (if (v2 <= v4) then (checkw (Queue (v5, v4, v3, v2, v1))) else (checkw (Queue (v3, (v4 + v2), ((APPEND v3) (REVERSE v1)), 0, Nil)))))) ;; let snoc = (fun v6 -> (fun v7 -> (match v6 with (Queue (v5, v4, v3, v2, v1)) -> (check (Queue (v5, v4, v3, (v2 + 1), (Cons (v7, v1)))))))) ;; let head = (fun x -> (match x with (Queue (v7, v6, v5, v4, v3)) -> (match v7 with Nil -> (raise (Match_failure (string_of_bool true, 0, 0))) | (Cons (v2, v1)) -> v2))) ;; let tail = (fun x -> (match x with (Queue (v7, v6, v5, v4, v3)) -> (match v7 with Nil -> (raise (Match_failure (string_of_bool true, 0, 0))) | (Cons (v2, v1)) -> (check (Queue (v1, (let k = (v6 - 1) in (if (k < 0) then 0 else k)), (TL v5), v4, v3)))))) ;;