Last active
August 29, 2015 14:14
-
-
Save JustinSDK/797094c6e3b16d510ffe to your computer and use it in GitHub Desktop.
〈Haskell Tutorial(21)來寫些迴圈吧!〉的解答
This file contains 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
while :: Bool -> IO () -> IO () | |
while cond value = do | |
if cond then value | |
else return () | |
forever' :: IO a -> IO () | |
forever' value = do | |
while True $ do | |
value | |
forever' value | |
sequence' :: [IO a] -> IO [a] | |
sequence' [] = return [] | |
sequence' (x:xs) = do | |
value <- x | |
values <- sequence' xs | |
return (value : values) | |
mapM' :: (a1 -> IO a) -> [a1] -> IO [a] | |
mapM' f xs = sequence' $ map f xs | |
mapM_' :: (a1 -> IO a) -> [a1] -> IO () | |
mapM_' f xs = do | |
mapM' f xs | |
return () | |
forM' :: [a1] -> (a1 -> IO a) -> IO [a] | |
forM' xs f = sequence' $ map f xs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment