Haskell: moving image on horizontal line

The fundamental algorithm is the same as your vertical shift function, since String is also a list of characters, [Char].

You can generalize your algorithm to a move function since the code for moveVer really only requires a list and has no dependency on Img:

move :: Int -> [a] -> [a]
move n xs = take len $ drop (mod n len) $ cycle xs
  where len = length xs

Now you can rewrite your moveVer function in terms of move:

moveVer :: Int -> Img -> Img
moveVer = move

And since a string is just a List of characters, you can map over the list of strings and use the move function to do your horizontal movement.

moveHor :: Int -> Img -> Img
moveHor n = map $ move n

Leave a Comment