crappy 99 bottles
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

74 líneas
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) = (\f -> conk [(f x), "bottle"] (' ':) $ [])
  13. | otherwise = (\f -> conk [(f x), "bottles"] (' ':) $ [])
  14. lyrc's'o :: String -> ((Integer -> String) -> String)
  15. lyrc's'o s = (\_ -> s)
  16. lyrc's :: (((Integer -> String) -> String), ((Integer -> String) -> String))
  17. lyrc's = (
  18. lyrc's'o "take one down",
  19. lyrc's'o "pass it around"
  20. )
  21. shic :: Integer ->
  22. (Integer -> ((Integer -> String) -> String)) ->
  23. String ->
  24. ((Integer -> String) -> String)
  25. shic x l w = (\f -> conk [l x $ f, w] (' ':) $[])
  26. lyrc'b :: Integer -> ((Integer -> String) -> String)
  27. lyrc'b x = shic x lyrc'b'o "of beer"
  28. lyrc'w :: Integer -> ((Integer -> String) -> String)
  29. lyrc'w x = shic x lyrc'b "of beer"
  30. lyrc :: Integer -> [((Integer -> String) -> String)]
  31. lyrc x = [
  32. lyrc'w x,
  33. lyrc'b x,
  34. fst stic,
  35. snd stic,
  36. lyrc'w (x-1)
  37. ]
  38. where
  39. stic = lyrc's
  40. thap :: (Integer -> String) -> ((Integer -> String) -> String) -> String
  41. thap f x = x f
  42. thop :: (Integer -> String) -> [((Integer -> String) -> String)] -> [String]
  43. thop f l = map (thap f) l
  44. --TO DO
  45. --edit this function to convert digits to english words
  46. tran :: Integer -> String
  47. tran = show
  48. beer :: Integer -> [String]
  49. beer x = thop (tran) (lyrc x)
  50. runSong :: Integer -> IO ()
  51. runSong 0 = return ()
  52. runSong x
  53. | x <= 0 = runSong 0
  54. | otherwise = do
  55. mapM_ putStrLn (beer x)
  56. putStrLn ""
  57. runSong (x-1)
  58. main :: IO ()
  59. main = runSong 10