module Queue_Sol (Queue, empty, isEmpty, enqueue, dequeue, toList) where data Queue a = Queue [a] [a] deriving Show empty :: Queue a empty = Queue [] [] isEmpty :: Queue a -> Bool isEmpty (Queue [] []) = True isEmpty _ = False enqueue :: a -> Queue a -> Queue a enqueue a (Queue hs ts) = Queue hs (a : ts) dequeue :: Queue a -> Maybe (a, Queue a) dequeue (Queue [] []) = Nothing dequeue (Queue [] ts) = dequeue $ Queue (reverse ts) [] dequeue (Queue (h:hs) ts) = Just (h, Queue hs ts) toList :: Queue a -> [a] toList (Queue hs ts) = hs ++ reverse ts