Is there a standard queue implementation for Haskell? I see several reasonably mature priority queue implementations, but no simple queues. Data.Sequence seems OK, but I assume we could get better performance with a more restricted datatype. Further, restricting the operations (ie, not a deque) can prevent bugs from dequeuing from the wrong end.
Edit:
To clarify, I was hoping for a mature Haskell implementation, preferably in Haskell Platform or Hackage.
Data.Queue was added to
base
in ghc 6.4 [1] and deprecated in ghc 6.6 [2] when it was subsumed byData.Sequence
.From the 6.6 release notes:
[1] https://downloads.haskell.org/~ghc/6.4/docs/html/users_guide/release-6-4.html
[2] https://downloads.haskell.org/~ghc/6.6/docs/html/users_guide/release-6-6.html
Okasaki in his book Purely Functional Data Structures, describes a FIFO queue as a pair of lists, front and back, where the front list contains the front elements of the queue in the correct order, and the back list contains the rear elements of the queue in the reverse order.
The idea is that new items are inserted to front of the back list, whereas values are popped out from the front list. If the front list becomes empty it is replaced by the reverse of the back list.
The queue maintains the invariance that the front list can be empty only if the back list is also empty; and performs amortized O(1).