Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.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 导入前奏曲函数,doctest说';不在范围内';_Haskell - Fatal编程技术网

Haskell 导入前奏曲函数,doctest说';不在范围内';

Haskell 导入前奏曲函数,doctest说';不在范围内';,haskell,Haskell,尝试使用Prelude的内置函数按空格分隔符列出字符串,如SO answer所述 我有以下资料: module MiniForth ( functions , ... ) where import Data.Char -- I actually import here import Prelude hiding (words) -- this avoids the ambiguity in the words function when declaring it locally

尝试使用Prelude的内置函数按空格分隔符列出字符串,如SO answer所述

我有以下资料:

module MiniForth
  ( functions
  , ...
  ) where
import Data.Char  -- I actually import here
import Prelude hiding (words) -- this avoids the ambiguity in the words function when declaring it locally

words :: String -> [String]
-- ^ Takes a string and breaks it into separate words delimited by a space
--
--   Examples:
--
--   >> words "break this string at spaces"
--   ["break","this","string","at","spaces"]
--
--   >> words ""
--   []
--
words s =  case dropWhile Char.isSpace s of
                      "" -> []
                      s' -> w : words s''
                            where (w, s'') = break Char.isSpace s'
但我在运行Doctest时仍然会出现错误:

Not in scope: ‘Char.isSpace’ 
两条线都有。我已经导入了它,为什么它不在范围内?

import Data.Char
isSpace
放入范围,不带
Char.
前缀。因此,移除所述前缀就足够了

否则,

import qualified Data.Char as Foo
将使用您选择的任何前缀
Foo.
Foo.isSpace
放入范围(以及导入的模块的其余部分)。

import Data.Char
isSpace
放入范围,不带
Char.
前缀。因此,移除所述前缀就足够了

否则,

import qualified Data.Char as Foo

将使用您选择的任何前缀
Foo.
Foo.isSpace
放入范围(以及导入的模块的其余部分)。

您已经得到了很好的建议,但作为进一步的解释,这里可能发生的情况是,您试图调整的代码使用了
Data.Char
模块的旧名称,即
Char
。(如果启用GHC的Haskell 98模式,仍然可以以这种方式导入。)

带有点的分层模块名称是在H98标准之后不久添加的,当人们看到完全扁平的模块名称空间是不切实际的时,这是一种事后思考。但这是以最小的方式完成的,只需在模块名称中添加
作为允许的字符

特别是,模块名在Haskell中是不可分割的:导入模块名
数据。Char
本身不允许您使用
Char
作为模块前缀


因此,如果您在执行导入数据.Char之后确实希望在
isSpace
之前包含模块前缀,那么它必须包含完整的模块名:
Data.Char.isSpace
,您已经得到了很好的建议,但作为进一步的解释,这里可能发生的情况是,您试图调整的代码使用了
Data.Char
模块的旧名称,即
Char
。(如果启用GHC的Haskell 98模式,仍然可以以这种方式导入。)

带有点的分层模块名称是在H98标准之后不久添加的,当人们看到完全扁平的模块名称空间是不切实际的时,这是一种事后思考。但这是以最小的方式完成的,只需在模块名称中添加
作为允许的字符

特别是,模块名在Haskell中是不可分割的:导入模块名
数据。Char
本身不允许您使用
Char
作为模块前缀


因此,如果在执行导入数据.Char之后确实希望在
isSpace
之前包含模块前缀,则必须包含完整的模块名:
Data.Char.isSpace

尝试删除
isSpace
前面的
Char.
。或者
导入符合条件的数据。Char作为Char
。将其作为答案抛出,我将奖励:)尝试删除
Char。
isSpace
前面。或者
导入符合条件的数据。Char as Char
。将其作为答案抛出,我将奖励:)