Created
January 11, 2012 23:10
-
-
Save sjoerdvisscher/1597375 to your computer and use it in GitHub Desktop.
A zipper for traversables.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Traversable | |
import Control.Monad.Free | |
import Control.Comonad | |
import Control.Comonad.Trans.Store | |
type Zipper t a = Free (Store a) (t a) | |
zipper :: Traversable t => t a -> Zipper t a | |
zipper = traverse (wrap . store return) | |
unzipper :: Zipper t a -> t a | |
unzipper = iter extract | |
step :: Maybe a -> Zipper t a -> Zipper t a | |
step _ (Pure t) = Pure t | |
step ma (Free s) = maybe extract peek ma s | |
test :: [Int] | |
test = unzipper . step (Just 10) . step Nothing . step (Just 20) $ zipper [1..10] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment