summaryrefslogtreecommitdiff
path: root/11-20/19.hs
blob: f1e795b36af910545dba69134afae90a6a87ccd0 (plain) (blame)
1
2
3
4
5
6
rotate :: [a] -> Int -> [a]

rotate l n = let (a, b) = rot l (if n < 0 then (n + length l) else n) in b ++ a
                 where rot l@(x:xs) n
                        | n > 0 = let (a, b) = rot xs (n - 1) in (x:a, b)
                        | otherwise = ([], l)