Ta tâche dans cet exercice est d'écrire du code qui renvoie les paroles de la chanson « The Twelve Days of Christmas ».
« The Twelve Days of Christmas » est un chant de Noël anglais très répandu. Chaque nouveau couplet de la chanson s'appuie sur le couplet précédent.
Les paroles renvoyées par ton code doivent correspondre exactement au texte complet de la chanson donné ci-dessous.
On the first day of Christmas my true love gave to me: a Partridge in a Pear Tree.
On the second day of Christmas my true love gave to me: two Turtle Doves, and a Partridge in a Pear Tree.
On the third day of Christmas my true love gave to me: three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
On the fourth day of Christmas my true love gave to me: four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
On the fifth day of Christmas my true love gave to me: five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
On the sixth day of Christmas my true love gave to me: six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
On the seventh day of Christmas my true love gave to me: seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
On the eighth day of Christmas my true love gave to me: eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
On the ninth day of Christmas my true love gave to me: nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
On the tenth day of Christmas my true love gave to me: ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
On the eleventh day of Christmas my true love gave to me: eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
On the twelfth day of Christmas my true love gave to me: twelve Drummers Drumming, eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.
Tu dois implémenter la fonction recite qui produit les paroles de « The Twelve Days of Christmas ». Tu peux utiliser la signature fournie si tu as un doute sur les types, mais ne la laisse pas brider ta créativité.
Cet exercice travaille sur des données textuelles. Pour des raisons historiques, le type String de Haskell est synonyme de [Char], une liste de caractères. Pour manipuler plus efficacement des données textuelles, on peut utiliser le type Text.
Comme prolongement facultatif à cet exercice, tu peux
- text à ta liste de dépendances dans package.yaml.Data.Text de la façon
suivante :import qualified Data.Text as T
import Data.Text (Text)
recite :: Int -> Int -> [Text] et faire référence aux
combinateurs de Data.Text comme par exemple T.pack.Data.Text.String par Text dans TwelveDays.hs, c'est-à-dire :recite :: Int -> Int -> [Text]
Cette partie est entièrement facultative.
Inscris-toi sur Exercism pour apprendre et maîtriser Haskell avec 107 exercices, et un vrai mentorat humain, le tout gratuitement.