Old lady swallowed a fly: Difference between revisions
m
→{{header|Haskell}}: Minor tweaks - mainly importing only tails, rather than whole Data.List library
m (→{{header|Haskell}}: Minor tweaks - mainly importing only tails, rather than whole Data.List library) |
|||
Line 924:
{{Works with|GHC|7.8.3}}
<lang haskell>
-- Once means the phrase is only printed in the verse about that animal.
Line 934 ⟶ 932:
-- Die is only used for the horse, and means the chain of animals won't be
-- included in the verse.
data AnimalAction
= Once
| Every
| Die
animals =
, ("fly", Every, "I don't know why she swallowed the fly.")
]
verse :: [(String, AnimalAction, String)] -> [String]
verse ((anim, act, phrase):restAnims) =
let lns = ["I know an old lady who swallowed a " ++ anim ++ ".", phrase]
in case act of
_ -> lns ++ verse' restAnims anim
verse' :: [(String, AnimalAction, String)] -> String -> [String]
Line 957 ⟶ 961:
verse' ((anim, act, phrase):restAnims) prevAnim =
let why = "She swallowed the " ++ prevAnim ++ " to catch the " ++ anim ++ "."
lns =
case act
Every -> [why, phrase]
_ -> [why]
in lns ++ verse' restAnims anim
song :: [String]
song = concatMap verse
main :: IO ()
main = putStr $ unlines song</lang>
|