Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.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
Haskell 什么';s";模棱两可;这里,我该如何修复它?_Haskell_Import_Variable Names - Fatal编程技术网

Haskell 什么';s";模棱两可;这里,我该如何修复它?

Haskell 什么';s";模棱两可;这里,我该如何修复它?,haskell,import,variable-names,Haskell,Import,Variable Names,我被告知要编写一个函数来检查字符串中的标点是否都是空格。i、 e: haskell> f "Hello my name is Brad" True haskell> f "Hello my name is Brad!" False 我写了一个辅助函数如下: import Data.Char isPunc x = not (isDigit x || isAlpha x) 哈斯克尔接受了这一点,而且效果很好。但当我在下面的函数中使用它时 --function f defined f

我被告知要编写一个函数来检查字符串中的标点是否都是空格。i、 e:

haskell> f "Hello my name is Brad"
True

haskell> f "Hello my name is Brad!"
False
我写了一个辅助函数如下:

import Data.Char
isPunc x = not (isDigit x || isAlpha x)
哈斯克尔接受了这一点,而且效果很好。但当我在下面的函数中使用它时

--function f defined
f :: String -> Bool
f xs = and [ x == ' ' | x <- xs, isPunc x]
我部分理解了它的抱怨,但是导入了数据。Char,我真的不明白为什么它会抱怨。

(这篇文章是在假设您真的将函数命名为
ispuncuation
,而不是
isPunc
)的情况下写的)

这是不明确的,因为Haskell不知道您在调用
ispuncation
时是指自己的
ispuncation
函数(
Main.ispuncation
)还是
Data.Char
ispuncation
函数。它是不明确的,因为您导入了
Data.Char
——如果您没有导入它或者导入了它符合条件,那么就不会有不明确的地方,因为
ispuncation
只能引用
Main.ispuncation


要修复歧义,请不要从
Data.Char
导入
ispuncutation
(通过将导入行更改为
import Data.Char hiding(ispuncutation)
),导入
Data.Char
限定(因此必须将其函数称为
Data.Char.functionName
),而不仅仅是
functionName
),或者为您的函数指定一个不同的名称,该名称与
Data.Char

Data.Char
模块的函数名为
ispuncation
。得到您提到的错误的唯一方法是,如果您将要创建的函数命名为相同的函数。您在这里给出的名称是
isPunc
,这应该很好,但我认为您实际使用了
ispuncuation。
使用其他名称或使用限定的导入:

import qualified Data.Char as Char

@迷你科技有吗?在我的安装中没有具有该名称的函数,文档中也没有列出它(尽管
ispunchuation
is)。请注意,OP的代码对我来说很好。Brad,你是否按原样发布了代码和错误消息?您没有在实际代码中将函数命名为
ispuncation
,然后在代码和错误消息中将其重命名为
isPunc
,是吗?
import qualified Data.Char as Char