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

Version Path
trackler-2.2.1.180 tracks/haskell/exercises/beer-song/examples/success-standard/src/Beer.hs
trackler-2.2.1.179 tracks/haskell/exercises/beer-song/examples/success-standard/src/Beer.hs
trackler-2.2.1.178 tracks/haskell/exercises/beer-song/examples/success-standard/src/Beer.hs
trackler-2.2.1.177 tracks/haskell/exercises/beer-song/examples/success-standard/src/Beer.hs
trackler-2.2.1.176 tracks/haskell/exercises/beer-song/examples/success-standard/src/Beer.hs
trackler-2.2.1.175 tracks/haskell/exercises/beer-song/examples/success-standard/src/Beer.hs
trackler-2.2.1.174 tracks/haskell/exercises/beer-song/examples/success-standard/src/Beer.hs
trackler-2.2.1.173 tracks/haskell/exercises/beer-song/examples/success-standard/src/Beer.hs
trackler-2.2.1.172 tracks/haskell/exercises/beer-song/examples/success-standard/src/Beer.hs
trackler-2.2.1.171 tracks/haskell/exercises/beer-song/examples/success-standard/src/Beer.hs
trackler-2.2.1.170 tracks/haskell/exercises/beer-song/examples/success-standard/src/Beer.hs
trackler-2.2.1.169 tracks/haskell/exercises/beer-song/examples/success-standard/src/Beer.hs
trackler-2.2.1.167 tracks/haskell/exercises/beer-song/examples/success-standard/src/Beer.hs
trackler-2.2.1.166 tracks/haskell/exercises/beer-song/examples/success-standard/src/Beer.hs
trackler-2.2.1.165 tracks/haskell/exercises/beer-song/examples/success-standard/src/Beer.hs
trackler-2.2.1.164 tracks/haskell/exercises/beer-song/examples/success-standard/src/Beer.hs
trackler-2.2.1.163 tracks/haskell/exercises/beer-song/examples/success-standard/src/Beer.hs
trackler-2.2.1.162 tracks/haskell/exercises/beer-song/examples/success-standard/src/Beer.hs
trackler-2.2.1.161 tracks/haskell/exercises/beer-song/examples/success-standard/src/Beer.hs
trackler-2.2.1.160 tracks/haskell/exercises/beer-song/examples/success-standard/src/Beer.hs