Skip to content

Instantly share code, notes, and snippets.

@puffnfresh
Last active August 29, 2015 13:58
Show Gist options
  • Save puffnfresh/10180396 to your computer and use it in GitHub Desktop.
Save puffnfresh/10180396 to your computer and use it in GitHub Desktop.
To fmap over a Data.Set just use Coyoneda!
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