Search code examples
haskellimportmodulecabalcabal-install

How do I install and test a Haskell package that I'm developing locally?


I'm developing a Haskell package and would like to test it as if it were an installed package. That is, I'd like to be able to install it among my other packages and then either import or :m +.

I can successfully build my package and (apparently) can successfully install it using

cabal install

which reports

Resolving dependencies...
Configuring Exos-0.0.1.0...
Building Exos-0.0.1.0...
Installed Exos-0.0.1.0

but all attempts to import the package then fail with something like (e.g. in GHCi)

<no location info>:
    Could not find module ‘Exos’
    It is not a module in the current program, or in any known package.

even though I can see a populated Exos-0.0.1.0 folder in my Haskell lib directory. (Even "uninstalling" fails with ghc-pkg unregister, which reports ghc-pkg: cannot find package Exos-0.0.1.0.)

How do I install and test a package that I'm developing locally, so that it behaves like part of my collection of installed Haskell packages — specifically so that I can import it (and "uninstall" it) like any other?


My package has the structure

Exos.cabal
Exos/
    Cryo/
        Exos.hs
        Exos/
            Display.hs
            Core.hs

with (relevant) contents in Exos.cabal

name:                   Exos
version:                0.0.1.0
build-type:             Simple
- ...

library
    exposed-modules:    Cryo.Exos,
                        Cryo.Exos.Display
    other-modules:      Cryo.Exos.Core
    -- other-extensions:
    build-depends:      base >=4.8,
                        containers >= 0.5.5.1,
                        split >= 0.2.2,
                        MissingH >= 1.3.0.1
    -- hs-source-dirs:
    default-language:   Haskell2010

in Exos.hs

module Cryo.Exos
    (
        f,
        g,
        otherFunc
    ) where

import Cryo.Exos.Core
-- ...

in Core.hs

module Cryo.Exos.Core where
-- ...

and in Display.hs

module Cryo.Exos.Display
    (
        showSomething,
        showSomethingElse
    ) where

import Data.Char
-- ...

import Cryo.Exos.Core
import Cryo.Exos

FWIW, inside my IDE, I can write an and successfully run "Application" with the following section in the above .cabal file

executable enigma-hs
    main-is:            Main.hs
    build-depends:      base >=4.8,
                        Exos
    hs-source-dirs:     tests
    default-language:   Haskell2010

and the following (relevant) code in Exos/tests/Main.hs

module Main where

import System.IO

import Cryo.Exos
import Cryo.Exos.Display

main :: IO ()
main = do
    putStr $ showSomething
    putStr $ showSomethingElse
    -- ...

Solution

  • The error is a simple one: If you look at the Main.hs example where you have successfully imported the module you have

    import Cryos.Expos
    

    and not

    import Expos    -- wrong
    

    that's because, the module you are importing is Cryos.Expos from the package Expos.