Okasaki描述了可以使用该类型在Haskell中实现的持久实时队列
data Queue a = forall x . Queue
{ front :: [a]
, rear :: [a]
, schedule :: [x]
}
Run Code Online (Sandbox Code Playgroud)
增量旋转保持不变量
length schedule = length front - length rear
Run Code Online (Sandbox Code Playgroud)
如果您熟悉所涉及的队列,则可以跳过本节.
旋转功能看起来像
rotate :: [a] -> [a] -> [a] -> [a]
rotate [] (y : _) a = y : a
rotate (x : xs) (y : ys) a =
x : rotate xs ys (y : a)
Run Code Online (Sandbox Code Playgroud)
它由智能构造函数调用
exec :: [a] -> [a] -> [x] -> Queue …Run Code Online (Sandbox Code Playgroud)