我正在创建一个给出Char
列表的函数,给出相同的列表但只包含数字:
algarismos :: [Char] -> [Char]
algarismos [] = []
algarismos (x:xs) | (isDigit x) =x:(algarismos xs)
| otherwise =(algarismos xs)
我收到错误消息
error: Variable not in scope: isDigit :: Char -> Bool
如果isDigit
存在,为什么说x
的范围不变?
答案 0 :(得分:4)
只要您提供所有代码,这就是实际的错误消息:
error: Variable not in scope: isDigit :: Char -> Bool
这说明isDigit
未定义,而不是其他任何内容。
您需要导入Data.Char
,其中包含isDigit
。把它放在文件的顶部:
import Data.Char (isDigit)
从基础模块isDigit
导入函数Data.Char
。
将来,请使用hoogle查找您需要进行的导入。