Language Haskell
(functional)
| Date: | 09/29/05 |
| Author: | Peter Kirby |
| URL: | http://www.peterkirby.com/ |
| Comments: | 2 |
| Info: | http://www.haskell.org/ |
| Score: |
module Main where
import Char(toUpper)
beers n | n == 0 = "no more bottles of beer"
| n == 1 = "1 more bottle of beer"
| otherwise = show n ++ " bottles of beer"
onwall n = beers n ++ " on the wall, " ++ beers n ++ ".\n"
around n | n == 0 = "go to the store and buy some more, " ++ beers 99 ++ " on the wall.\n"
| otherwise = "take one down and pass it around, " ++ beers (n-1) ++ " on the wall.\n"
capitalize s = [toUpper(head s)] ++ (tail s)
verse n = capitalize (onwall n) ++ capitalize (around n) ++ "\n"
main = putStr $ concatMap verse [99, 98 .. 0]
Download Source | Write Comment
Alternative Versions
| Version | Author | Date | Comments | Rate |
|---|---|---|---|---|
| Using guards | Simon Johansson | 10/25/07 | 1 | |
| 2 | Iavor | 03/03/06 | 3 | |
| With monads and monad transformer | Adrien Piérard | 12/25/06 | 2 |
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
beers 0 = "no more bottles of beer"
beers 1 = "1 more bottle of beer"
beers n = show n ++ " bottles of beer"
capitalize (x:xs) = toUpper x : xs
etc.