【发布时间】:2017-10-24 08:01:18
【问题描述】:
我有三个文件。第一个:
module AST where
data Prog a b = ...
第二个
module ParseProg where
import qualified AST as A
progToAST :: String -> A.Prog String String
这是用于家庭作业的包的一部分。我安装了它
$ cabal configure
$ cabal build
$ cabal install
这似乎奏效了。我的第三个程序(测试)是
import ParseProg
val1 = progToAST "x"
-- prog :: A.Prog String String
fun1 :: Int -> Int
fun1 x = 2
-- val2 = fun1 val1
所以导入工作。如果我取消注释 prog,我会得到 p>
Not in scope: type constructor or class ‘A.Prog’
如果我尝试 Prog 或 AST.Prog,也是一样。检查 val1 获取的类型
> :type val1
> val1 :: CabParser-0.1.0.0:AST.Prog String String
同样取消注释 val2 给出
Couldn't match expected type ‘Int’
with actual type ‘CabParser-0.1.0.0:AST.Prog String String’
复制 CabParser-0.1.... 会出现解析错误。如何在 AST 中使用 Prog 数据类型?
【问题讨论】:
-
第三个程序中没有
import qualified AST as A。 -
现在我得到
"Could not find module ‘AST’ it is a hidden module in the package ‘CabParser-0.1.0.0@CabPa_<nonsense> -
您必须在您的
.cabal文件中为CabParser列出它。我不记得字段名称,但ParseProg已经列在其中了。 -
是的,没错。
-
太好了,这行得通。如果您将其写成答案,我会接受。否则我可以做到。
标签: haskell