Total real-time persistent queues
问题 Okasaki describes persistent real-time queues which can be realized in Haskell using the type data Queue a = forall x . Queue { front :: [a] , rear :: [a] , schedule :: [x] } where incremental rotations maintain the invariant length schedule = length front - length rear More details If you're familiar with the queues involved, you can skip this section. The rotation function looks like rotate :: [a] -> [a] -> [a] -> [a] rotate [] (y : _) a = y : a rotate (x : xs) (y : ys) a = x : rotate xs ys