In questo esercizio il tuo compito è scrivere del codice che restituisca il testo della canzone «The Twelve Days of Christmas».
«The Twelve Days of Christmas» è un canto di Natale inglese molto diffuso. Ogni strofa successiva si basa su quella precedente.
Il testo restituito dal codice deve corrispondere esattamente al testo completo della canzone mostrato qui sotto.
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.
Devi implementare la funzione recite, che restituisce il testo di «The Twelve Days of Christmas». Puoi usare la firma fornita se hai dubbi sui tipi, ma non lasciare che limiti la tua creatività.
Questo esercizio lavora con dati testuali. Per ragioni storiche, il tipo String di Haskell è sinonimo di [Char], una lista di caratteri. Per gestire i dati testuali in modo più efficiente si può usare il tipo Text.
Come estensione facoltativa di questo esercizio, puoi
- text alla tua lista di dipendenze in package.yaml.Data.Text nel modo seguente:import qualified Data.Text as T
import Data.Text (Text)
recite :: Int -> Int -> [Text] e riferirti ai combinatori di Data.Text come ad es. T.pack.Data.Text.String con Text in TwelveDays.hs, cioè:recite :: Int -> Int -> [Text]
Questa parte è del tutto facoltativa.
Iscriviti a Exercism per imparare e padroneggiare Haskell con 107 esercizi e il mentoring di persone reali, tutto gratis.