它来自另一个问题,但情况发生了变化。
Parsec 函数“parse”和“Stream”类的类型签名
我现在想知道如何import
使事情变得不同。
文件:RunParse.hs
module RunParse where
import System.IO
import Data.Functor.Identity (Identity)
----import Text.Parsec () ....................(1)
----import Text.Parsec ....................(2)
import Text.Parsec.Prim (Parsec, parse, Stream)
runIOParse :: (Show a) => Parsec String () a -> String -> IO ()
runIOParse pa fn =
do
inh <- openFile fn ReadMode
outh <- openFile (fn ++ ".parseout") WriteMode
instr <- hGetContents inh
let result = case parse pa fn instr of
Right rs -> show rs
Left err -> "error"
hPutStr outh result
hClose inh
hClose outh
(我使用的是 ghc 7.0.4)
将文件加载到 ghci 中:
> :l RunParse.hs
它告诉我:
RunParse.hs:13:23:
Could not deduce (Stream String Identity t0)
arising from a use of `parse'
from the context (Show a)
bound by the type signature for
runIOParse :: Show a => Parsec String () a -> String -> IO ()
at RunParse.hs:(8,1)-(18,15)
Possible fix:
add (Stream String Identity t0) to the context of
the type signature for
runIOParse :: Show a => Parsec String () a -> String -> IO ()
or add an instance declaration for (Stream String Identity t0)
In the expression: parse pa fn instr
In the expression:
case parse pa fn instr of {
Right rs -> show rs
Left err -> "error" }
In an equation for `result':
result
= case parse pa fn instr of {
Right rs -> show rs
Left err -> "error" }
然后我添加了(1)或(2):
import Text.Parsec () ....................(1)
import Text.Parsec ....................(2)
然后:l RunParse
,加载成功。
然后我删除所有(1)和(2),然后:l RunParse
,仍然成功!
然后我:q
退出了ghci,重启了ghci,和启动一样,加载失败。
这是 ghc 的错误,还是我应该了解更多import
?
PS RunParse.hs 在ghc -c --make RunParse.hs
没有 (1) 和 (2) 的情况下失败了。