【发布时间】:2014-09-27 14:07:14
【问题描述】:
尝试使用 Prelude 的内置函数按空格分隔符列出字符串,如 SO answer here 所述。
我有以下几点:
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’
两行。我已经导入了,为什么不在范围内?
【问题讨论】:
-
尝试删除
isSpace前面的Char.。或import qualified Data.Char as Char. -
把它当做答案,而且是错误的奖励:)
标签: haskell