Created
July 21, 2014 14:22
-
-
Save sjoerdvisscher/a5e37ca223a21c9981ef to your computer and use it in GitHub Desktop.
List traversal with hask
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
listTraversal :: (Strong p, Monoidal (p [a])) => p a b -> p [a] [b] | |
listTraversal p = dimap f g $ _2 $ ap2 (nil, cons) | |
where | |
f as = (as, as) | |
g ([], (bs, _)) = bs | |
g (_ , (_, bs)) = bs | |
nil = return [] | |
cons = return (:) `ap` lmap Prelude.head p `ap` lmap Prelude.tail (listTraversal p) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment