1 (* Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh
2 * Jagannathan, and Stephen Weeks.
4 * MLton is released under a BSD-style license.
5 * See the file MLton-LICENSE for details.
7 (*-------------------------------------------------------------------*)
9 (*-------------------------------------------------------------------*)
11 (* Error. on Okasaki93, Okasaki96 *)
13 (* reverses tail before it is needed *)
15 functor EarlyQueue(AR: APPEND_REVERSE): BASIC_PERSISTENT_QUEUE =
21 datatype 'a t = T of 'a AR.t * 'a L.t
24 if AR.length l >= L.length r then T(l, r)
25 else T(AR.appendReverse(l, r), L.empty())
27 fun empty() = T(AR.empty(), L.empty())
29 fun isEmpty(T(l, _)) = AR.isEmpty l
31 fun destruct(T(l, r)) =
34 | SOME(x, l) => SOME(x, queue(l, r))
36 fun enque(T(l, r), x) = queue(l, L.cons(x, r))