presentation-fp-haskell/12days.hs
2020-01-09 02:19:41 +01:00

23 lines
860 B
Haskell

gifts :: [String]
gifts =
[ "And a partridge in a pear tree!", "Two turtle doves,", "Three french hens,"
, "Four calling birds,", "Five golden rings,", "Six geese a-laying,"
, "Seven swans a-swimming,", "Eight maids a-milking,", "Nine ladies dancing,"
, "Ten lords a-leaping,", "Eleven pipers piping,", "Twelve drummers drumming,"
]
days :: [String]
days = [
"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth",
"ninth", "tenth", "eleventh", "twelfth" ]
verseOfTheDay :: Int -> String
verseOfTheDay day =
"On the " ++ days !! day ++ " day of Christmas my true love gave to me... \n"
++ concat (map (++ "\n") [dayGift day d | d <- [day, day-1..0]]) ++ "\n"
where
dayGift 0 _ = "A partridge in a pear tree!"
dayGift _ gift = gifts !! gift
main :: IO ()
main = putStrLn (concatMap verseOfTheDay [0..11])