Joa*_*nte -2 variables haskell scope char
我正在创建一个函数,该函数给定的列表Char,给出相同的列表,但仅带有数字:
algarismos :: [Char] -> [Char]
algarismos [] = []
algarismos (x:xs) | (isDigit x) =x:(algarismos xs)
| otherwise =(algarismos xs)
Run Code Online (Sandbox Code Playgroud)
我收到错误消息
error: Variable not in scope: isDigit :: Char -> Bool
Run Code Online (Sandbox Code Playgroud)
为什么说isDigit如果x存在,则范围没有变量?
只要您将所有代码都提供给我们,这就是实际的错误消息:
error: Variable not in scope: isDigit :: Char -> Bool
Run Code Online (Sandbox Code Playgroud)
这就是说isDigit没有定义,没有别的。
您需要导入Data.Char,其中包含isDigit。将其放在文件顶部:
import Data.Char (isDigit)
Run Code Online (Sandbox Code Playgroud)
这isDigit将从基本模块导入功能Data.Char。