Language Haskell
(Using guards)
Date: | 10/25/07 |
Author: | Simon Johansson |
URL: | n/a |
Comments: | 3 |
Info: | n/a |
Score: | (3.02 in 175 votes) |
--Version of http://99-bottles-of-beer.net/language-haskell-1070.html --using guards. bottles :: Int -> String bottles n |n == 0 = "no more bottles" |n == 1 = "1 bottle" |n > 1 = show n ++ " bottles" verse :: Int -> String verse n |n == 0 = "No more bottles of beer on the wall, no more bottles of beer.\n" ++ "Go to the store and buy some more, 99 bottles of beer on the wall." |n>0 = bottles n ++ " of beer on the wall, " ++ bottles n ++ " of beer.\n" ++ "Take one down and pass it around, " ++ bottles (n-1) ++ " of beer on the wall.\n" main = mapM (putStrLn . verse) [99,98..0]
Download Source | Write Comment
Alternative Versions
Version | Author | Date | Comments | Rate |
---|---|---|---|---|
1 | Iavor | 03/03/06 | 5 | |
With monads and monad transformer | Adrien Piérard | 12/25/06 | 2 | |
Using list comprehension | Ben Firner | 11/21/08 | 0 |
Download Source | Write Comment
Add Comment
Please provide a value for the fields Name,
Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.
Please don't post large portions of code here! Use the form to submit new examples or updates instead!
Comments
George said on 05/27/08 15:37:26
This is actually really nice.
When the time is right im dropping imperative for functional programming.
Neil Kandalgaonkar said on 06/02/09 00:10:07
The useless definition of bottles 0 bothers me.
said on 06/12/09 19:49:15
Neil, the definition of bottles 0 is useful, in the verse for 1 bottle.