Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Variables Haskell:变量的作用域_Variables_Haskell_Scope_Char - Fatal编程技术网

Variables Haskell:变量的作用域

Variables Haskell:变量的作用域,variables,haskell,scope,char,Variables,Haskell,Scope,Char,我正在创建一个函数,该函数给定一个Char列表,给出相同的列表,但仅包含数字: algarismos :: [Char] -> [Char] algarismos [] = [] algarismos (x:xs) | (isDigit x) =x:(algarismos xs) | otherwise =(algarismos xs) 我收到了错误信息 error: Variable not in scope: isDigit :: Char -

我正在创建一个函数,该函数给定一个
Char
列表,给出相同的列表,但仅包含数字:

algarismos :: [Char] -> [Char]

algarismos [] = []
algarismos (x:xs) | (isDigit x) =x:(algarismos xs)
                  |  otherwise =(algarismos xs)
我收到了错误信息

error: Variable not in scope: isDigit :: Char -> Bool

如果
x
存在,为什么会说
isDigit
在作用域中没有变量?

只要您给我们所有的代码,这就是实际的错误消息:

error: Variable not in scope: isDigit :: Char -> Bool
这意味着,
isDigit
没有定义,没有其他定义


您需要导入
Data.Char
,其中包含
isDigit
。将此项放在文件的顶部:

import Data.Char (isDigit)
这将从基本模块
Data.Char
导入函数
isDigit


将来,请使用查找需要进行的导入。

实际错误消息是什么?请始终包含实际错误消息。-您遇到的问题可能不在范围内。您是否实际导入了
Data.Char
?错误:变量不在范围内:isDigit::Char->Bool | 6 | algarismos(x:xs)|(isDigit x)=x:(algarismos xs)根据我的经验,与其他语言相比,Haskell代码的示例更可能假定您知道哪些导入是示例工作所必需的(并了解要安装哪个第三方库才能使导入工作)。