Sha256: 4203d90959dcad82dd59f3aad4569bfa192e46f75353480d603897ecbcd51737
Contents?: true
Size: 884 Bytes
Versions: 395
Compression:
Stored size: 884 Bytes
Contents
module Beer (song) where import Data.Char (toUpper) import Data.List (intercalate) capitalize :: String -> String capitalize (h : t) = toUpper h : t capitalize [] = [] bottles :: Int -> String bottles 1 = "bottle" bottles _ = "bottles" countBottles :: Int -> String countBottles 0 = "no more" countBottles n = show n stanza :: Int -> String stanza n | n >= 0 = countBottles n ++ " " ++ bottles n ++ " of beer" | otherwise = stanza 99 it :: Int -> String it 1 = "it" it _ = "one" action :: Int -> String action n | n > 0 = "Take " ++ it n ++ " down and pass it around" | otherwise = "Go to the store and buy some more" verse :: Int -> String verse n = unlines [ capitalize (stanza n) ++ " on the wall, " ++ stanza n ++ "." , action n ++ ", " ++ stanza (pred n) ++ " on the wall." ] song :: String song = intercalate "\n" $ map verse [99, 98 .. 0]
Version data entries
395 entries across 395 versions & 1 rubygems