この演習の課題は、「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.
'The Twelve Days of Christmas'の歌詞を出力するrecite関数を実装する必要があります。型について不安があるときは、用意されているシグネチャを使ってもかまいませんが、それに創造性を縛られないようにしましょう。
この演習では、テキストデータを扱います。歴史的な理由から、HaskellのString型は、文字の配列である[Char]と同じ意味です。テキストデータをより効率的に扱うには、Text型を使えます。
この演習の任意の発展として、次のことができます。
import qualified Data.Text as T
import Data.Text (Text)
recite :: Int -> Int -> [Text]と書き、Data.TextのコンビネーターをT.packのように参照する。Data.Textのドキュメントを調べる。StringをすべてTextに置き換える。つまり次のとおりです。recite :: Int -> Int -> [Text]
この部分は完全に任意です。