Σε αυτή την άσκηση, το καθήκον σου είναι να γράψεις κώδικα που επιστρέφει τους στίχους του τραγουδιού: "The Twelve Days of Christmas."
Το "The Twelve Days of Christmas" είναι ένα γνωστό αγγλικό χριστουγεννιάτικο τραγούδι. Κάθε επόμενη στροφή βασίζεται στην προηγούμενη.
Οι στίχοι που επιστρέφει ο κώδικάς σου πρέπει να ταιριάζουν ακριβώς με το πλήρες κείμενο του τραγουδιού που φαίνεται παρακάτω.
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.
Πρέπει να υλοποιήσεις τη συνάρτηση recite που βγάζει τους στίχους του
"The Twelve Days of Christmas". Μπορείς να χρησιμοποιήσεις την υπογραφή που
σου δίνεται αν δεν είσαι σίγουρος για τους τύπους, αλλά μην την αφήσεις να
περιορίσει τη δημιουργικότητά σου.
Αυτή η άσκηση έχει να κάνει με κειμενικά δεδομένα. Για ιστορικούς λόγους, ο
τύπος String της Haskell είναι συνώνυμος με το [Char], μια λίστα από
χαρακτήρες. Για πιο αποδοτικό χειρισμό κειμενικών δεδομένων, μπορείς να
χρησιμοποιήσεις τον τύπο Text.
Ως προαιρετική επέκταση αυτής της άσκησης, μπορείς να
- text στη λίστα εξαρτήσεών σου στο package.yaml.Data.Text με τον παρακάτω
τρόπο:import qualified Data.Text as T
import Data.Text (Text)
recite :: Int -> Int -> [Text] και να αναφέρεσαι στους
συνδυαστές του Data.Text ως π.χ. T.pack.Data.Text.String με Text στο TwelveDays.hs, δηλαδή:recite :: Int -> Int -> [Text]
Αυτό το μέρος είναι εντελώς προαιρετικό.
Γράψου στο Exercism για να μάθεις και να κατακτήσεις Haskell με 107 ασκήσεις και πραγματική καθοδήγηση από ανθρώπους, όλα δωρεάν.