-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Queue data structures.
--
-- Queue data structures, as described in
--
--
-- - Okasaki, Chris. "Simple and efficient purely functional queues and
-- deques." Journal of functional programming 5.4 (1995):
-- 583-592.
-- - Okasaki, Chris. Purely Functional Data Structures. Diss.
-- Princeton University, 1996.
--
--
-- A queue has a "back" where new elements are enqueued, and a "front"
-- where elements are dequeued in the order that they were enqueued (last
-- in, first out).
--
-- The queues provided in this library also support an "enqueue at front"
-- operation, because the underlying representations happen to support
-- it, so you might technically refer to these data structures as
-- output-restricted deques.
--
-- In this library, it is helpful to think of the "front" being on the
-- left, because (though the direction is arbitrary) we are
-- consistent throughout, where it matters:
--
--
-- - List conversion functions associate the head of a list with the
-- front of a queue.
-- - The append operator xs <> ys creates a queue with
-- xs in front of ys.
-- - The Show instances draw the front of the queue on the
-- left.
--
--
-- Under "ephemeral" (or "single-threaded", or "linear") usage, wherein
-- one does not need to refer to an old version of a data structure after
-- mutating it:
--
--
-- - EphemeralQueue is 2.5x faster than and
-- allocates 0.50x as much memory as Queue.
-- - Queue is 2.6x faster than and allocates 0.40x
-- as much memory as Seq (from containers).
--
--
-- (These numbers vary from benchmark to benchmark and machine to
-- machine. Always perform your own experiments!)
--
-- While it is certainly common to use a queue ephemerally, it is unusual
-- for a Haskell data structure to require ephemeral usage to achieve its
-- stated bounds. A refactoring or change in requirements might cause
-- surprising changes in performance. That is why EphemeralQueue
-- has a longer name and module name. When in doubt, use Queue.
@package queues
@version 1.0.0
-- | A queue data structure with <math> (worst-case) operations, as
-- described in
--
--
-- - Okasaki, Chris. "Simple and efficient purely functional queues and
-- deques." Journal of functional programming 5.4 (1995):
-- 583-592.
-- - Okasaki, Chris. Purely Functional Data Structures. Diss.
-- Princeton University, 1996.
--
module Queue
-- | A queue data structure with <math> (worst-case) operations.
data Queue a
-- | An empty queue.
pattern Empty :: Queue a
-- | The front of a queue, and the rest of it.
pattern Full :: a -> Queue a -> Queue a
-- | An empty queue.
empty :: Queue a
-- | A singleton queue.
singleton :: a -> Queue a
-- | <math>. Construct a queue from a list. The head of the list
-- corresponds to the front of the queue.
fromList :: [a] -> Queue a
-- | <math>. Enqueue an element at the back of a queue, to be
-- dequeued last.
enqueue :: a -> Queue a -> Queue a
-- | <math> front, <math> rest. Dequeue an element from the
-- front of a queue.
dequeue :: Queue a -> Maybe (a, Queue a)
-- | <math>. Enqueue an element at the front of a queue, to be
-- dequeued next.
enqueueFront :: a -> Queue a -> Queue a
-- | <math>. Is a queue empty?
isEmpty :: Queue a -> Bool
-- | <math>. Apply a function to every element in a queue.
map :: (a -> b) -> Queue a -> Queue b
-- | <math>. Apply a function to every element in a queue.
traverse :: Applicative f => (a -> f b) -> Queue a -> f (Queue b)
-- | <math>. Construct a list from a queue. The head of the list
-- corresponds to the front of the queue.
toList :: Queue a -> [a]
instance GHC.Base.Functor Queue.Queue
instance GHC.Classes.Eq a => GHC.Classes.Eq (Queue.Queue a)
instance Data.Foldable.Foldable Queue.Queue
instance GHC.Base.Monoid (Queue.Queue a)
instance GHC.Base.Semigroup (Queue.Queue a)
instance GHC.Show.Show a => GHC.Show.Show (Queue.Queue a)
instance Data.Traversable.Traversable Queue.Queue
-- | A queue data structure with <math> (amortized under ephemeral
-- usage only) operations, as described in
--
--
-- - Okasaki, Chris. "Simple and efficient purely functional queues and
-- deques." Journal of functional programming 5.4 (1995):
-- 583-592.
-- - Okasaki, Chris. Purely Functional Data Structures. Diss.
-- Princeton University, 1996.
--
module Queue.Ephemeral
-- | A queue data structure with <math> (amortized under ephemeral
-- usage only) operations.
data EphemeralQueue a
-- | An empty queue.
pattern Empty :: EphemeralQueue a
-- | The front of a queue, and the rest of it.
pattern Full :: a -> EphemeralQueue a -> EphemeralQueue a
-- | An empty queue.
empty :: EphemeralQueue a
-- | A singleton queue.
singleton :: a -> EphemeralQueue a
-- | <math>. Construct a queue from a list. The head of the list
-- corresponds to the front of the queue.
fromList :: [a] -> EphemeralQueue a
-- | <math>. Enqueue an element at the back of a queue, to be
-- dequeued last.
enqueue :: a -> EphemeralQueue a -> EphemeralQueue a
-- | <math> front, <math> rest. Dequeue an element from the
-- front of a queue.
dequeue :: EphemeralQueue a -> Maybe (a, EphemeralQueue a)
-- | <math>. Enqueue an element at the front of a queue, to be
-- dequeued next.
enqueueFront :: a -> EphemeralQueue a -> EphemeralQueue a
-- | <math>. Is a queue empty?
isEmpty :: EphemeralQueue a -> Bool
-- | <math>. Apply a function to every element in a queue.
map :: (a -> b) -> EphemeralQueue a -> EphemeralQueue b
-- | <math>. Apply a function to every element in a queue.
traverse :: Applicative f => (a -> f b) -> EphemeralQueue a -> f (EphemeralQueue b)
-- | <math>. Construct a list from a queue. The head of the list
-- corresponds to the front of the queue.
toList :: EphemeralQueue a -> [a]
instance GHC.Base.Functor Queue.Ephemeral.EphemeralQueue
instance GHC.Classes.Eq a => GHC.Classes.Eq (Queue.Ephemeral.EphemeralQueue a)
instance Data.Foldable.Foldable Queue.Ephemeral.EphemeralQueue
instance GHC.Base.Monoid (Queue.Ephemeral.EphemeralQueue a)
instance GHC.Base.Semigroup (Queue.Ephemeral.EphemeralQueue a)
instance GHC.Show.Show a => GHC.Show.Show (Queue.Ephemeral.EphemeralQueue a)
instance Data.Traversable.Traversable Queue.Ephemeral.EphemeralQueue