Created
May 15, 2010 14:32
-
-
Save NicolasT/402219 to your computer and use it in GitHub Desktop.
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
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