试图使用Prelude的内置函数来通过空格分隔符来判定一个字符串,如SO回答here所述。导入前奏功能,doctest说'不在范围内'
我有以下几点:
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'
但运行文档测试时,我仍然得到错误:
两条线路。我输入了它,为什么它不在范围内?
尝试删除'isSpace'前面的'Char.'。或'将合格的Data.Char导入为Char'。 – chi 2014-09-27 14:36:15
把它当作答案扔进去,而且生病了:) – 2014-09-27 14:58:58