(********************************************************************)
(*  OCaml code from the book ``Learn Programming with OCaml''       *)
(*  See https://usr.lmf.cnrs.fr/lpo/                                *)
(*                                                                  *)
(*  Sylvain Conchon and Jean-Christophe Filliâtre                   *)
(*  Copyright 2025 Université Paris-Saclay and CNRS                 *)
(*                                                                  *)
(*  Openly licensed via CC BY SA 4.0                                *)
(*  See https://creativecommons.org/licenses/by-sa/4.0/deed.en      *)
(********************************************************************)

(* Program 60 on page 275
   Persistent queues represented by pairs of lists *)

  type 'a t = 'a list * 'a list

  let empty =
    ([], [])

  let is_empty = function
    | [], [] -> true
    | _ -> false

  let push x (o, i) =
    (o, x :: i)

  let pop = function
    | [], [] ->
        invalid_arg "pop"
    | x :: o, i ->
        x, (o, i)
    | [], i ->
        match List.rev i with
        | x :: o -> x, (o, [])
        | [] -> assert false

This document was generated using caml2html