This commit is contained in:
Shaun Kerr 2019-03-12 13:06:52 +13:00
commit 62d06d47c4
2 changed files with 82 additions and 0 deletions

17
README.md Normal file
View File

@ -0,0 +1,17 @@
# Crappy 99 Bottles
99 bottles poem implemented in Haskell, making use of fun concepts.
im so sorry
## compiling
`ghc beer.hs`
## running
`./beer`
## author
tA

65
beer.hs Normal file
View File

@ -0,0 +1,65 @@
vape :: [a] -> ([a] -> [a])
vape (x:xs) = (x:) . (vape xs)
vape [] = id
conk :: Eq a => [[a]] -> ([a] -> [a]) -> ([a] -> [a])
conk (x:xs) f = (vape x) . (sep xs f) . (conk xs f)
where
sep x l = if (x == []) then id else l
conk [] _ = id
lyrc'b'o :: Integer -> ((Integer -> String) -> String)
lyrc'b'o x
| (x == 0) = (\_ -> "no more bottles")
| (x == 1) = (\f -> conk [(f x), "bottle"] (' ':) $ [])
| otherwise = (\f -> conk [(f x), "bottles"] (' ':) $ [])
lyrc's'o :: String -> ((Integer -> String) -> String)
lyrc's'o s = (\_ -> s)
lyrc's :: (((Integer -> String) -> String), ((Integer -> String) -> String))
lyrc's = (
lyrc's'o "take one down",
lyrc's'o "pass it around"
)
lyrc'b :: Integer -> ((Integer -> String) -> String)
lyrc'b x = (\f -> conk [lyrc'b'o x $ f, "of beer"] (' ':) $[])
lyrc'w :: Integer -> ((Integer -> String) -> String)
lyrc'w x = (\f -> conk [lyrc'b x $ f, "on the wall"] (' ':) $[])
lyrc :: Integer -> [((Integer -> String) -> String)]
lyrc x = [
lyrc'w x,
lyrc'b x,
fst stic,
snd stic,
lyrc'w (x-1)
]
where
stic = lyrc's
thap :: (Integer -> String) -> ((Integer -> String) -> String) -> String
thap f x = x f
thop :: (Integer -> String) -> [((Integer -> String) -> String)] -> [String]
thop f l = map (thap f) l
tran :: Integer -> String
tran = show
beer :: Integer -> [String]
beer x = thop (tran) (lyrc x)
runSong :: Integer -> IO ()
runSong 0 = return ()
runSong x
| x <= 0 = runSong 0
| otherwise = do
mapM_ putStrLn (beer x)
putStrLn ""
runSong (x-1)
main :: IO ()
main = runSong 10