Hello Haskell community,
I'm new to Haskell and ran into a problem when I tried to structure my first bigger project.
Here's the minimal example of the problem (I'm using cabal to build).
This is the directory structure of a simple module:
FooMod1
|- FooMod1.cabal
|- Setup.hs
|- src
|- FooMod1.hs
|- FooMod1
|- C1.hs
|- T1.hs
The source for FooMod1.hs:
module FooMod1 (
C1(..) ,
T1(..) ,
) where
import FooMod1.C1
import FooMod1.T1
The source for C1.hs:
module FooMod1.C1 (
C1(..)
) where
class C1 a where
c1FooFun :: a -> IO ()
The source for 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"
The source for the cabal file:
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
and the Setup.hs:
module Main where
import Distribution.Simple
main = defaultMain
I can do
cabal configure
cabal build
cabal install
without any problem. When I start ghci and
import FooMod1
it loads the module and I can see the data constructors. But when I try to get the type of a function for example
:t c1FooFun
or construct a value I get:
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' reveals nothing.
What am I missing? I looked it up in the Haskell 2010 Standard (http://www.haskell.org/onlinereport/haskell2010/haskellch5.html) and i can't find the error. So my questions are
1) Why am I getting this error?
2) Is structuring a hierarchical modules like that good practice? (assume considerably larger programs)
Many thanks in advance!
Jules
other-modules:
line. You have only told it about theFooMod1
module. I'm not sure why this isn't a compile error. – asm