地图功能无法在此行上运行
compPic (a:as) = map (compL a) as
它只适用于单个字符串,但不能在字符串列表中找到错误。
compL :: String -> String
compL bs = [a | b <- bs, a <-
if (b == ' ')
then "X"
else if (b=='X')
then " "
else [b]]
compPic :: [String] -> [String]
compPic [] = []
compPic (a:as) = map (compL a) as
答案 0 :(得分:2)
让我们看一下map
中Prelude
的定义:
map _ [] = []
map f (x:xs) = f x : map f xs
在这里,我们看到map
被定义为将列表中的每个值传递给正在应用的函数。此外,我们不需要基本情况,因为map
处理递归。因此,您应该将compPic
重写为:
compPic :: [String] -> [String]
compPic as = map compL as
或者,eta-reduced:
compPic = map compL