Last active
August 29, 2015 13:58
-
-
Save puffnfresh/10180396 to your computer and use it in GitHub Desktop.
To fmap over a Data.Set just use Coyoneda!
This file contains hidden or 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
module SetFunctor where | |
import Data.Functor.Coyoneda | |
import Data.Set | |
setF :: Coyoneda Set Int | |
setF = liftCoyoneda $ fromList [1, 2, 3] | |
runCoyendaSet :: Ord a => Coyoneda Set a -> Set a | |
runCoyendaSet (Coyoneda f s) = fromList . fmap f $ toList s | |
main :: IO () | |
main = print . runCoyendaSet . fmap (+1) $ fmap (`div` 2) setF | |
-- fromList [1,2] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment