control-monad-queue-0.1: Reusable corecursive queues, via continuations.

Maintainerleon at melding-monads dot com



A library implementation of corecursive queues, see Circular Programs and Self-Referential Structures by Lloyd Allison, Software Practice and Experience, 19(2), pp.99-109, Feb 1989

For an explanation of the library implementation, see Lloyd Allison's Corecursive Queues: Why Continuations Matter by Leon P Smith, in The Monad Reader, Issue 14. This library corresponds to CorecQ in that paper.



data Q e a Source


MonadQueue e (Q e) 
Monad (Q e) 

runQueue :: Q e a -> [e]Source

Returns a list of all elements enqueued during the queue computation

enQ :: e -> Q e ()Source

Enqueues an element to the queue

deQ :: Q e (Maybe e)Source

Dequeues an element, returns Nothing if the queue is empty.

deQs :: Integral len => len -> Q e [e]Source

Dequeues up to len elements from the queue

deQ_break :: Q e eSource

Dequeues an element: terminates the queue computation if the queue is empty.

peekQ :: Q e (Maybe e)Source

Examines the front element of the queue without removing it.

peekQn :: Integral index => index -> Q e (Maybe e)Source

Examines the element currently at position index in the queue, indexing starts with 0, like !!.

peekQs :: Integral maxlen => maxlen -> Q e [e]Source

Examines up to maxlen elements of the queue without removing them.

lenQ :: Integral len => Q e lenSource

Returns the length of the queue

lenQ_ :: Q e LenTypeSource

Returns the length of the queue

callCC :: ((a -> forall b. Q e b) -> Q e a) -> Q e aSource

exit :: Q e aSource

Terminates the queue computation