1

I installed the timezone-series Haskell module using cabal install timezone-series-0.1.5.1.

I then defined a module named Main.hs that starts with:

import Data.Time.LocalTime.TimeZone.Series -- from timezone-series-0.1.5.1

when I run ghc Main.hs, GHC throws the following error:

/home/ubuntu/Main.hs:2:1: error:
    Failed to load interface for ‘Data.Time.LocalTime.TimeZone.Olson’

I tried explicitly including the cabal directory in GHC's search path using:

ghc -i/home/ubuntu/.cabal/lib/x86_64-linux-ghc-8.0.2/timezone-olson-0.2.0-KqRNJj3zomR7zz2Yx6P5Oq/ Main.hs

This resulted in the correct path being searched, but GHC is only looking for files ending in the suffix ".hs":

Locations searched:
...
      /home/ubuntu/.cabal/lib/x86_64-linux-ghc-8.0.2/timezone-olson-0.2.0-KqRNJj3zomR7zz2Yx6P5Oq/Data/Time/LocalTime/TimeZone/Series.hs
      /home/ubuntu/.cabal/lib/x86_64-linux-ghc-8.0.2/timezone-olson-0.2.0-KqRNJj3zomR7zz2Yx6P5Oq/Data/Time/LocalTime/TimeZone/Series.lhs
      /home/ubuntu/.cabal/lib/x86_64-linux-ghc-8.0.2/timezone-olson-0.2.0-KqRNJj3zomR7zz2Yx6P5Oq/Data/Time/LocalTime/TimeZone/Series.hsig
      /home/ubuntu/.cabal/lib/x86_64-linux-ghc-8.0.2/timezone-olson-0.2.0-KqRNJj3zomR7zz2Yx6P5Oq/Data/Time/LocalTime/TimeZone/Series.lhsig

Cabal installed interface files instead however:

 /home/ubuntu/.cabal/lib/x86_64-linux-ghc-8.0.2/timezone-olson-0.2.0-KqRNJj3zomR7zz2Yx6P5Oq/Data/Time/LocalTime/TimeZone/Olson.hi

From line 318 of GHC's source code it looks like GHC ignores "*.hi" files unless it is called in single-shot mode (with the -c flag). Is this correct? (See: https://github.com/ghc/ghc/blob/67a5a91ef5e61f3b3c84481d8a396ed48cd5d96e/compiler/GHC/Unit/Finder.hs)

How can I get GHC to import this module?

An help will be greatly appreciated!

  • 1
    I'd recommend you compile/run with `cabal` instead of `GHC` directly - it'll provide the right compiler-flags for you – Random Dev May 25 '21 at 06:26
  • 2
    Try creating a local package environment https://stackoverflow.com/questions/63837574/haskell-could-not-find-module-test-quickcheck/63841684#63841684 But creating a full-blown Cabal package might be the best solution in the long run. https://cabal.readthedocs.io/en/3.4/developing-packages.html#using-cabal-init – danidiaz May 25 '21 at 07:28

1 Answers1

2

My suggested ways of installing packages in order of my preference:

  1. Make a cabal package and add timezone-series you want to install to the build-depends field as described in the cabal manual.

  2. Use the experimental cabal-env tool to basically automate the process of point 3 below, but then with the global environment. This makes a new build-plan every time you install a new package, so it is like removing the package environment and building it again with all the old packages and the new package added to it. You can add specific constraints like this: cabal-env "timezone-series == 0.1.5.1".

  3. Install a package into local package environment with cabal --package-env . --lib timezone-series. You can add as many packages as you want after the --lib option to install more than one package. If you later want to use a different set of packages simply remove the .ghc.environment.* file that is generated and rerun the installation with a new set of packages. GHC will automatically use these package environment files that are in the current or parent directories. You can specify specific constraints with the --constraint option like this: --constraint "timezone-series == 0.1.5.1".

  4. Use cabal install --lib timezone-series to install it directly into the global environment (~/.ghc/x86_64-linux-8.0.2/environments/default), this will fail if a conflicting package was installed earlier. When you run into errors you can remove that package environment and try again.

Finally, I want to note that GHC 8.0.2 is quite old, so I would advise you to upgrade if you don't have a specific reason for using that version.

Noughtmare
  • 9,410
  • 1
  • 12
  • 38
  • Thanks @Noughtmare. I'm testing these options now and will upvote your answer as soon as one of them works. – user2136374 May 25 '21 at 12:20
  • Perhaps my version of cabal is out of date, but when I run `cabal install --lib --package-env . timezone-series` I get the folloring error message: `cabal: option --lib is ambiguous; could be one of: ...` Any idea why? – user2136374 May 25 '21 at 12:49
  • You will need to use `v2-install` or `new-install` (they both do the same thing) if you're using cabal-install versions older than 3.0.0.0. And I think my answer does not work at all for cabal versions older than 2.0.0.0. – Noughtmare May 25 '21 at 13:19
  • @user2136374 but please, try the other options first. As the answer says, `install --lib` is the least preferrable one. – leftaroundabout May 25 '21 at 15:02