Perhaps one additional tip to the one given (use unfoldr) is to perhaps
conceptualise it differently. Consider the function duplicate:
duplicate :: ListZipper a -> ListZipper (ListZipper a)
duplicate = extend id
extend :: (ListZipper a -> b) -> ListZipper a -> ListZipper b
extend f = fmap f . duplicate
You can see that you can write duplicate and extends in terms of each
other, so if you can write one, you can easily recover the other.
Therefore, perhaps think of the problem in terms of duplicate. The
duplicate function takes a zipper and produces a zipper that contains
all possible zippers. You can get all these zippers by moving left and
right from the original zipper. Sometimes you won't be able to move
left/right because you at the end. The move function will return Maybe.
That's when you want to stop producing zippers. Maybe is also used to
indicate to unfoldr to stops producing values.
--
Tony Morris
http://tmorris.net/