你好哈斯克尔社区,
我是 Haskell 的新手,当我尝试构建我的第一个更大的项目时遇到了问题。
这是问题的最小示例(我正在使用 cabal 来构建)。
这是一个简单模块的目录结构:
FooMod1
|- FooMod1.cabal
|- Setup.hs
|- src
|- FooMod1.hs
|- FooMod1
|- C1.hs
|- T1.hs
FooMod1.hs 的来源:
module FooMod1 (
C1(..) ,
T1(..) ,
) where
import FooMod1.C1
import FooMod1.T1
C1.hs的来源:
module FooMod1.C1 (
C1(..)
) where
class C1 a where
c1FooFun :: a -> IO ()
T1.hs的来源:
module FooMod1.T1 (
T1(..)
) where
import FooMod1.C1
data T1 = T1 deriving(Show)
instance C1 T1 where
c1FooFun T1 = putStrLn "c1FooFun from T1"
cabal 文件的来源:
Name: FooMod1
Version: 0.0.1
Cabal-version: >=1.10
Build-type: Simple
library
build-depends: base >= 4 && < 5
if impl(ghc >= 7.0.0)
default-language: Haskell2010
ghc-options: -Wall
exposed-modules: FooMod1
ghc-options: -Wall -rtsopts
hs-source-dirs: src, src/FooMod1
default-language: Haskell2010
和Setup.hs:
module Main where
import Distribution.Simple
main = defaultMain
我可以
cabal configure
cabal build
cabal install
没有任何问题。当我启动 ghci 时
import FooMod1
它加载模块,我可以看到数据构造函数。
但是当我尝试获取函数的类型时
:t c1FooFun
或构造一个我得到的值:
Failed to load interface for `FooMod1.C1'
There are files missing in the `FooMod1-0.0.1' package,
try running 'ghc-pkg check'.
Use -v to see a list of the files searched for.
In the expression: c1FooFun
“ghc-pkg check”没有透露任何内容。
我缺少什么?我在 Haskell 2010 Standard 中查找了它(http://www.haskell.org/onlinereport/haskell2010/haskellch5.html http://www.haskell.org/onlinereport/haskell2010/haskellch5.html),我找不到错误。所以我的问题是
1)为什么我会收到此错误?
2)构建分层模块是一种好的做法吗? (假设相当大的程序)
提前谢谢了!
Jules