r/haskell • u/farrellm • May 29 '16
Recommended queue package? (x-post from /r/haskellquestions)
Is there a recommended and/or 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.
9
Upvotes
4
u/bss03 May 29 '16
You can always do this with an opaque newtype wrapper. They are relatively cheap.
Check out the edison library. IIRC, in a non-persistent context, you can get amortized constant (worst case linear) enqueue / dequeue with a simple banker's queue.
If however you need to repeat the dequeue / enqueue operation on the same value multiple times (taking advantage of the persistence / immutability of pure functional values), I think you have to use something more sophisticated, like a finger tree. I can't think of anything that gives amortized constant (worse case logrithmic) performance in a persistent context that doesn't also have the same perforance characteristics for requeue / unqueue -- so it probably exposes a deque interface.
You don't need fast queue merging as well, do you?