{-# LANGUAGE MultiParamTypeClasses, TypeSynonymInstances #-} module CircularShifter where import LineStorage import qualified Data.IntMap as IntMap class CircularShifter s t r where shift :: (s (t e)) -> (s (r (t e))) rotate :: [a] -> [a] rotate [] = [] rotate (x:xs) = xs ++ [x] rotateAll :: [a] -> [[a]] rotateAll xs = take (length xs) (iterate rotate xs) instance CircularShifter StorageList StorageList StorageList where shift (ListStorage es) = ListStorage $ map shift_ es where shift_ (ListStorage es) = ListStorage $ map ListStorage $ rotateAll es instance CircularShifter StorageMap StorageMap StorageMap where shift m = IntMap.map (toMap . map toMap . rotateAll . IntMap.elems) m where toMap = foldl add IntMap.empty