Created
January 7, 2014 14:03
-
-
Save myuon/8299739 to your computer and use it in GitHub Desktop.
whileを使ったループ(多分分かりやすくはない)
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
import Control.Monad | |
while :: (Monad m) => (a -> Bool) -> m a -> m a | |
while f m = do | |
a <- m | |
when (f a) $ while f m >> return () | |
return $ a | |
main = do | |
putStrLn $ "Can you guess the number I have?" | |
while (\a -> a /= 42) $ do | |
a <- getLine | |
putStrLn $ "You said:" ++ a | |
return $ read a | |
putStrLn "That's right!" |
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
Can you guess the number I have? | |
> 10 | |
You said:10 | |
> 20 | |
You said:20 | |
> 43 | |
You said:43 | |
> 42 | |
You said:42 | |
That's right! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment