A procrastinating queue. You can populate the back of the queue in
IO and read the front of the queue in pure code. The front of an
empty, unclose
d queue is _|_
. I think it fits the definition of
referentially transparent, but it's possible to do some really
stupid things with one of these Queue
s. If you read the source,
this serves as an example of using Data.PVar.Structure. Here's a
simple example of using a Queue
:
import Prelude hiding (sum) import Data.Foldable (sum) main :: IO () main = do (back, front) <- newQueue -- Create a new queue. mapM_ (push back) [0..9] -- Push some values to the back of the queue. print $ peek front -- Safe to do since we know something has been written close back -- Close the queue. print $ sum front -- Safe to do since the queue is finalized
The output of the above program is:
Just 0 45
Is this useful? Who knows? It was a fun exercise.
Documentation
A pure queue.