GHC cannot find module in cabal sandbox

I am using Haskell version 7.8.4 on (X) Ubuntu 15.10, with Cabal-Install 1.18 installed via apt . I did not try to install anything related to Haskell manually on this machine. I created a sandbox from the cab, pulled out and installed the module only to find that ghc did not seem to pick it up. ghc -v it looks like I have two versions of the cabal library that mutually overshadow each other. How it works?

I start with an empty directory /tmp/haskell-example

then i do a cabal sandbox init .

 $ cabal sandbox init Writing a default package environment file to /tmp/haskell-example/cabal.sandbox.config Creating a new sandbox at /tmp/haskell-example/.cabal-sandbox 

then I set natural-numbers because I want to use the Data.Natural module in the program. This operation succeeds.

 $ cabal install natural-numbers Resolving dependencies... Notice: installing into a sandbox located at /tmp/haskell-example/.cabal-sandbox Configuring natural-numbers-0.1.2.0... Building natural-numbers-0.1.2.0... Installed natural-numbers-0.1.2.0 

I can verify that the Data.Natural module Data.Natural really installed in the cabal sandbox.

 $ ls /tmp/haskell-example/.cabal-sandbox/lib/x86_64-linux-ghc-7.8.4/natural-numbers-0.1.2.0 Data libHSnatural-numbers-0.1.2.0.a libHSnatural-numbers-0.1.2.0-ghc7.8.4.so $ ls /tmp/haskell-example/.cabal-sandbox/lib/x86_64-linux-ghc-7.8.4/natural-numbers-0.1.2.0/Data Natural.dyn_hi Natural.hi 

then I create a simple Main.hs file that imports Data.Natural but does not use it.

 module Main where import Data.Natural main = putStrLn "Hello World" 

When I try ghc Main.hs , I see the following:

 $ ghc Main.hs Main.hs:3:8: Could not find module 'Data.Natural' Use -v to see a list of the files searched for. 

With the flag turned on, it seems like my bondage is obscured by a later cab, which in turn obscures the previous bondage. Why is this happening?

 $ ghc -v Main.hs Glasgow Haskell Compiler, Version 7.8.4, stage 2 booted by GHC version 7.8.4 Using binary package database: /usr/lib/ghc/package.conf.d/package.cache hiding package Cabal-1.18.1.5 to avoid conflict with later version Cabal-1.22.1.1 wired-in package ghc-prim mapped to ghc-prim-0.3.1.0-ec14d2f6075975a2ce9112eae431c8e1 wired-in package integer-gmp mapped to integer-gmp-0.5.1.0-de4898ebdc5ab81cedce89121ae9ac84 wired-in package base mapped to base-4.7.0.2-5ef1e7e809bc3b18d74efc783356e209 wired-in package rts mapped to builtin_rts wired-in package template-haskell mapped to template-haskell-2.9.0.0-c1976a420ad8b9b589eee08844c59ba2 wired-in package dph-seq not found. wired-in package dph-par not found. Hsc static flags: hiding package Cabal-1.18.1.5 to avoid conflict with later version Cabal-1.22.1.1 wired-in package ghc-prim mapped to ghc-prim-0.3.1.0-ec14d2f6075975a2ce9112eae431c8e1 wired-in package integer-gmp mapped to integer-gmp-0.5.1.0-de4898ebdc5ab81cedce89121ae9ac84 wired-in package base mapped to base-4.7.0.2-5ef1e7e809bc3b18d74efc783356e209 wired-in package rts mapped to builtin_rts wired-in package template-haskell mapped to template-haskell-2.9.0.0-c1976a420ad8b9b589eee08844c59ba2 wired-in package dph-seq not found. wired-in package dph-par not found. *** Chasing dependencies: Chasing modules from: *Main.hs Main.hs:3:8: Could not find module 'Data.Natural' Locations searched: Data/Natural.hs Data/Natural.lhs *** Deleting temp files: Deleting: *** Deleting temp dirs: Deleting: 
+5
source share
1 answer

If you are involved in manual hacking, you can pass ghc the location of pkg db sandbox, for example:

 ghc Main.hs -package-db .cabal-sandbox/x86_64-linux-ghc-7.10.2-packages.conf.d/ 

However, the “normal” way of using sandboxes is always compiled using cabal build (or cabal install without parameters), and not directly using ghc.

  • Run cabal init , answer the questions as you wish.
  • Edit the resulting foo.cabal file ( foo is the name of your package).
  • Run cabal build or cabal install - this will launch ghc for you.

When editing a cabal file, make sure that you export the modules (if it is lib) and that your main src is correct. Also make sure that dependencies such as natural-numbers are listed in the build-depends: clause.

+6
source

Source: https://habr.com/ru/post/1237542/


All Articles