Skip to content

Instantly share code, notes, and snippets.

@MiyamonY
Created February 27, 2015 09:36
Show Gist options
  • Save MiyamonY/9277e94c8e3c1c46b5c3 to your computer and use it in GitHub Desktop.
Save MiyamonY/9277e94c8e3c1c46b5c3 to your computer and use it in GitHub Desktop.
import Control.Monad
import Data.Char
main :: IO ()
-- putStr
-- main = do
-- putStr "Hey, "
-- putStr "I'm "
-- putStr "Andy!"
-- putChar
-- main = do
-- putChar 't'
-- putChar 'e'
-- putChar 'h'
-- putStr :: String -> IO ()
-- putStr [] = return ()
-- putStr (x :: xs) = do
-- putChar x
-- putStr xs
-- print
-- main = do
-- print True
-- print 2
-- print "haha"
-- print 3.2
-- print [3, 4, 3]
-- when
-- when :: Monad m => Bool -> m () -> m ()
-- main = do
-- input <- getLine
-- when (input == "SWORDFISH") $ do
-- putStrLn input
-- main = do
-- input <- getLine
-- if input == "SWORDFISH"
-- then putStrLn input
-- else return ()
-- sequence
-- sequence :: Monad m => [m a] -> m [a]
-- main = do
-- a <- getLine
-- b <- getLine
-- c <- getLIne
-- print (a, b, c)
-- main = do
-- rs <- sequence [getLine, getLine, getLine]
-- print rs
-- mapM
-- mapM :: Monad m => (a -> m b) -> [a] -> m [b]
-- mapM_ :: Monad m => (a -> m b) -> [a] -> m ()
-- forever
-- forever :: Monad m => m a -> m b
-- mai = forever $ do
-- putStr "Give me some input: "
-- l <- getLine
-- putStrLn $ map toUpper l
-- forM
-- forM :: Monad m => [a] -> (a -> m b) -> m [b]
main = do
colors <- forM [1,2,3,4] $ \ a -> do
putStrLn $ "Which color do you associate with the number " ++ show a ++ "?"
color <- getLine
return color
putStrLn "The colors that you associate with 1, 2, 3 and 4 are: "
mapM_ putStrLn colors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment