Skip to content

Instantly share code, notes, and snippets.

@debasishg
Created June 6, 2010 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save debasishg/427707 to your computer and use it in GitHub Desktop.
Save debasishg/427707 to your computer and use it in GitHub Desktop.
module BatchedQueue (BatchedQueue) where
import Prelude hiding (head, tail)
import Queue
data BatchedQueue a = BQ [a] [a]
check [] r = BQ (reverse r) []
check f r = BQ f r
instance Queue BatchedQueue where
empty = BQ [] []
isEmpty (BQ f r) = null f
snoc (BQ f r) x = check f (x : r)
head (BQ [] _) = error "empty queue"
head (BQ (x : f) r) = x
tail (BQ [] _) = error "empty queue"
tail (BQ (x : f) r) = check f r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment