(* This code extends 'mini_prelude'. *) type ('a) status = Finished of ('a) list | Appending of int * ('a) list * ('a) list | Reversing of int * ('a) list * ('a) list * ('a) list * ('a) list | Idle ;; let exec = (fun v22 -> (match v22 with Idle -> Idle | (Reversing (v13, v12, v11, v10, v9)) -> (match v12 with Nil -> (match v10 with Nil -> (Reversing (v13, Nil, v11, Nil, v9)) | (Cons (v4, v3)) -> (match v3 with Nil -> (Appending (v13, v11, (Cons (v4, v9)))) | (Cons (v2, v1)) -> (Reversing (v13, Nil, v11, (Cons (v4, (Cons (v2, v1)))), v9)))) | (Cons (v8, v7)) -> (match v10 with Nil -> (Reversing (v13, (Cons (v8, v7)), v11, Nil, v9)) | (Cons (v6, v5)) -> (Reversing ((v13 + 1), v7, (Cons (v8, v11)), v5, (Cons (v6, v9)))))) | (Appending (v20, v19, v18)) -> (if (v20 <= 0) then (match v19 with Nil -> (Finished (v18)) | (Cons (v15, v14)) -> (Finished (v18))) else (match v19 with Nil -> (Appending (v20, Nil, v18)) | (Cons (v17, v16)) -> (Appending ((v20 - 1), v16, (Cons (v17, v18)))))) | (Finished (v21)) -> (Finished (v21)))) ;; let invalidate = (fun v12 -> (match v12 with Idle -> Idle | (Reversing (v5, v4, v3, v2, v1)) -> (Reversing ( (let k = (v5 - 1) in (if (k < 0) then 0 else k)), v4, v3, v2, v1)) | (Appending (v10, v9, v8)) -> (if (v10 <= 0) then (match v8 with Nil -> (Appending (0, v9, Nil)) | (Cons (v7, v6)) -> (Finished (v6))) else (Appending ((v10 - 1), v9, v8))) | (Finished (v11)) -> (Finished (v11)))) ;; type ('a) queue = Queue of int * ('a) list * ('a) status * int * ('a) list ;; let exec2 = (fun v15 -> (match v15 with (Queue (v14, v13, v12, v11, v10)) -> (match (exec (exec v12)) with Idle -> (Queue (v14, v13, Idle, v11, v10)) | (Reversing (v5, v4, v3, v2, v1)) -> (Queue (v14, v13, (Reversing (v5, v4, v3, v2, v1)), v11, v10)) | (Appending (v8, v7, v6)) -> (Queue (v14, v13, (Appending (v8, v7, v6)), v11, v10)) | (Finished (v9)) -> (Queue (v14, v9, Idle, v11, v10))))) ;; let check = (fun v7 -> (match v7 with (Queue (v6, v5, v4, v3, v2)) -> (if (v3 <= v6) then (exec2 (Queue (v6, v5, v4, v3, v2))) else (let v1 = (Reversing (0, v5, Nil, v2, Nil)) in (exec2 (Queue ((v6 + v3), v5, v1, 0, Nil))))))) ;; let empty = (Queue (0, Nil, Idle, 0, Nil)) ;; let is_empty = (fun v1 -> (fun v2 -> (fun v3 -> (fun v4 -> (fun v5 -> (v1 = 0)))))) ;; 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 v6 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 v6 with Nil -> (raise (Match_failure (string_of_bool true, 0, 0))) | (Cons (v2, v1)) -> (check (Queue ( (let k = (v7 - 1) in (if (k < 0) then 0 else k)), v1, (invalidate v5), v4, v3)))))) ;;