Skip to content

Instantly share code, notes, and snippets.

@monoid
Created August 27, 2011 09:35
Show Gist options
  • Select an option

  • Save monoid/1175189 to your computer and use it in GitHub Desktop.

Select an option

Save monoid/1175189 to your computer and use it in GitHub Desktop.
Old hack: list queue
data Q a = Q [a] [a] deriving Show -- head and reversed tail
emptyQ = Q [] []
enQ a (Q h t) = Q h (a:t)
popQ (Q [] []) = error "Empty queue"
popQ (Q (a:h) t) = (a, Q h t)
popQ (Q [] t) = popQ (Q (reverse t) [])
toList (Q h t) = h ++ (reverse t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment