Skip to content

Instantly share code, notes, and snippets.

@NicolasT
Created May 15, 2010 14:32
Show Gist options
  • Save NicolasT/402219 to your computer and use it in GitHub Desktop.
Save NicolasT/402219 to your computer and use it in GitHub Desktop.
f :: Monad m => m Int -> m Bool
f a = do
b <- a
return $ b == 0
f' :: Functor f => f Int -> f Bool
f' = fmap helper
where
helper = (== 0)
main :: IO ()
main = do
dump $ Just 10
dump $ Just 0
dump Nothing
dump []
dump [-2, -1 .. 2]
where
dump :: (Monad m, Functor m, Show (m Bool), Show (m Int)) => m Int -> IO ()
dump a = do
putStrLn ("f(" ++ show a ++ "): " ++ show (f a))
putStrLn ("f'(" ++ show a ++ "): " ++ show (f' a))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment