It is necessary to implement the function that sets the cyclic rotation of the list. If the integer argument is positive, the rotation should be to the left, and negative, to the right.
Prelude> rotate 2 "abcdefghik" "cdefghikab" Prelude> rotate (-2) "abcdefghik" "ikabcdefgh"
You also need to ensure the performance on endless lists (for scenarios when it makes sense) and reasonable efficiency with a large number of rotations of a small list:
Prelude> :set +s Prelude> rotate 1234567890 [1..10] [1,2,3,4,5,6,7,8,9,10] (0.00 secs, 0 bytes)
I made this decision:
rotate :: Int -> [a] -> [a] rotate _ [] = [] rotate 0 xs = xs rotate n xs = bs ++ as where (as, bs) = splitAt (n `mod` length xs) xs
But unfortunately it is not effective:
Failed test #1. Run time error: main: out of memory (requested 1048576 bytes)
What can there be an effective solution?