嘿.对于本周的教程,其中一个问题要求通过使用其他函数formatLine和formatList来创建函数formatLines,以格式化行列表.
我的代码看起来像这样;
type Line = String
formatLine :: Line -> String
formatLine l = l ++ "\n"
formatList :: (a -> String) -> [a] -> String
formatList f [] = []
formatList f xs = f (head xs) ++ formatList f (tail xs)
formatLines :: [Line] -> String
formatLines xs = formatList formatLine xs
Run Code Online (Sandbox Code Playgroud)
代码看起来(至少对我来说)它应该工作,但不是创建一个新的行,其中"\n",\n被附加到字符串.
任何帮助将不胜感激.
我在教程中得到了这个问题,我真的不知道如何去做.
为了确保
filter p . map f = map g . filter h
始终保持,必须如何用p和f定义g和h ?
任何指向正确方向的人都会非常感激.