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 *)
13 (* reverses tail before it is needed
14 and walks down list incrementally *)
16 functor IncrementalQueue(AR: APPEND_REVERSE)
17 : BASIC_PERSISTENT_QUEUE =
23 datatype 'a t = T of 'a AR.t * 'a AR.t * 'a L.t
31 if AR.length l >= L.length r then T(l, l', r)
32 else let val l = AR.appendReverse(l, r)
36 fun empty() = let val l = AR.empty()
40 fun isEmpty(T(l, _, _)) = AR.isEmpty l
42 fun destruct(T(l, l', r)) =
45 | SOME(x, l) => SOME(x, queue(l, l', r))
47 fun enque(T(l, l', r), x) = queue(l, l', L.cons(x, r))