{-# OPTIONS -XTemplateHaskell -XMultiParamTypeClasses #-} import UpdatableViewStub {-# LINE 4 "../examples/queue.hs" #-} data Q a = None | More a (Q a) deriving (Show, Eq) {-# LINE 21 "../examples/queue.hs" #-} data Qi a = Qi [a] [a] deriving (Show, Eq) instance UpdatableView (Qi a ) (Q a ) where {-# LINE 33 "../examples/queue.hs" #-} view = $(foldT ''Qi) ( (idB <**> reverseB) >>>> appendB) >>>> l2l where l2l = $(foldT ''[]) ( $(toC 'None) <||> $(toC 'More) ) isEmpty :: Q a -> Bool isEmpty None = True emptyQ :: Q a emptyQ = None enQ :: a -> Q a -> Q a enQ = let enQ a (Qi x y) = Qi x (a:y) in (toView :: (a -> Qi a -> Qi a ) -> (a -> Q a -> Q a )) enQ deQ :: Q a -> Q a deQ = let deQ (Qi (a:x) y) = Qi x y deQ (Qi [] y) = deQ (Qi (reverse y) []) in (toView :: (Qi a -> Qi a) -> (Q a -> Q a)) deQ first :: Q a -> a first = let first (Qi (a:x) y) = a first (Qi [] y) = first (Qi (reverse y) []) in (toView :: (Qi a -> a ) -> (Q a -> a )) first {-# LINE 36 "../examples/queue.hs" #-} mapQ f None = None mapQ f (More a x) = More (f a) (mapQ f x) play1 0 q = first q play1 (n+1) q = do hd play1 n (enQ hd tl) where hd = first q tl = deQ q