Sample types:
isDigit :: Monad f => Char -> f Bool
any :: Monad f => (a -> f Bool) -> [a] -> f Bool
reverse :: Monad f => [a] -> f [a]
map :: Monad f => (a -> f b) -> [a] -> f [b]
"hello" :: Monad f => f String
putStrLn :: (MonadIO f) => String -> f ()
show :: (Show a,Monad f) => a -> f String
identify :: Monad m => Identity a -> m a
identify = return . runIdentity
Translation:
apply | haskell
f x y | do x' <- x
| y' <- y
| f x y
if f x | do x' <- f x
then y | if x'
else z | then y
| else z
case f x of | do x' <- f x
_ -> _ | case x of ...
do x <- a | do x <- fmap return a
y <- b | y <- fmap return b
Examples:
main :: IO ()
main = putStrLn (show (if any isDigit "hello"
then map isDigit "hello"
else reverse "hello"))
main :: IO ()
main = putStrLn (identify (show (if any isDigit "hello"
then map isDigit "hello"
else reverse "hello")))
main :: IO ()
main = do
name <- getLine
age <- getLine
putStrLn ("Your name is " ++ name ++ " and your age is " ++ age)
main :: IO ()
main = do
putStrLn ("Your name is " ++ getLine ++ " and your age is " ++ getLine)