crappy 99 bottles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.8KB

  1. vape :: [a] -> ([a] -> [a])
  2. vape (x:xs) = (x:) . (vape xs)
  3. vape [] = id
  4. conk :: Eq a => [[a]] -> ([a] -> [a]) -> ([a] -> [a])
  5. conk (x:xs) f = (vape x) . (sep xs f) . (conk xs f)
  6. where
  7. sep x l = if (x == []) then id else l
  8. conk [] _ = id
  9. lyrc'b'o :: Integer -> ((Integer -> String) -> String)
  10. lyrc'b'o x
  11. | (x == 0) = (\_ -> "no more bottles")
  12. | (x == 1) = cenk "bottle" x
  13. | otherwise = cenk "bottles" x
  14. where
  15. cenk s x = (\f -> conk [(f x), s] (' ':) $ [])
  16. lyrc's'o :: String -> ((Integer -> String) -> String)
  17. lyrc's'o s = (\_ -> s)
  18. lyrc's :: (((Integer -> String) -> String), ((Integer -> String) -> String))
  19. lyrc's = (
  20. lyrc's'o "take one down",
  21. lyrc's'o "pass it around"
  22. )
  23. shic :: Integer ->
  24. (Integer -> ((Integer -> String) -> String)) ->
  25. String ->
  26. ((Integer -> String) -> String)
  27. shic x l w = (\f -> conk [l x $ f, w] (' ':) $[])
  28. lyrc'b :: Integer -> ((Integer -> String) -> String)
  29. lyrc'b x = shic x lyrc'b'o "of beer"
  30. lyrc'w :: Integer -> ((Integer -> String) -> String)
  31. lyrc'w x = shic x lyrc'b "on the wall"
  32. lyrc :: Integer -> [((Integer -> String) -> String)]
  33. lyrc x = [
  34. lyrc'w x,
  35. lyrc'b x,
  36. fst stic,
  37. snd stic,
  38. lyrc'w (x-1)
  39. ]
  40. where
  41. stic = lyrc's
  42. thap :: (Integer -> String) -> ((Integer -> String) -> String) -> String
  43. thap f x = x f
  44. thop :: (Integer -> String) -> [((Integer -> String) -> String)] -> [String]
  45. thop f l = map (thap f) l
  46. --TO DO
  47. --edit this function to convert digits to english words
  48. tran :: Integer -> String
  49. tran = show
  50. beer :: Integer -> [String]
  51. beer x = thop (tran) (lyrc x)
  52. runSong :: Integer -> IO ()
  53. runSong 0 = return ()
  54. runSong x
  55. | x <= 0 = runSong 0
  56. | otherwise = do
  57. mapM_ putStrLn (beer x)
  58. putStrLn ""
  59. runSong (x-1)
  60. main :: IO ()
  61. main = runSong 10