Haskell GHC在阴谋集团沙箱中找不到模块

Haskell GHC在阴谋集团沙箱中找不到模块,haskell,ghc,cabal,cabal-install,Haskell,Ghc,Cabal,Cabal Install,我在(X)Ubuntu 15.10上使用Haskell版本7.8.4,Cabal安装1.18都是通过apt安装的。我没有尝试在这台机器上手动安装任何与Haskell相关的东西。我建立了一个阴谋集团的沙箱,获取并安装了一个模块,结果发现ghc似乎没有接收到它ghc-v似乎暗示我有两个版本的阴谋集团库,它们相互隐藏。这是怎么回事 我从一个空目录开始/tmp/haskell示例 然后我做了一个cabalsandboxinit $ cabal sandbox init Writing a default

我在(X)Ubuntu 15.10上使用Haskell版本7.8.4,Cabal安装1.18都是通过
apt
安装的。我没有尝试在这台机器上手动安装任何与Haskell相关的东西。我建立了一个阴谋集团的沙箱,获取并安装了一个模块,结果发现
ghc
似乎没有接收到它
ghc-v
似乎暗示我有两个版本的阴谋集团库,它们相互隐藏。这是怎么回事

我从一个空目录开始
/tmp/haskell示例

然后我做了一个
cabalsandboxinit

$ 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
然后我安装了
natural number
,因为我想在程序中使用
Data.natural
模块。此操作成功

$ 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
我可以确认
Data.Natural
模块确实已安装到阴谋集团沙箱中

$ 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
然后我创建一个简单的
Main.hs
文件,该文件导入
Data.Natural
,但不使用它

module Main where

import Data.Natural

main = putStrLn "Hello World"
当我尝试
ghc Main.hs
时,我看到以下内容:

$ ghc Main.hs 
Main.hs:3:8:
    Could not find module ‘Data.Natural’
    Use -v to see a list of the files searched for.
启用了详细标志后,我的阴谋集团似乎被一个后来的阴谋集团所跟踪,而这个阴谋集团反过来又在跟踪先前的阴谋集团。为什么会这样

$ 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: 

如果您对手动黑客感兴趣,可以将沙箱的pkg db位置传递给ghc,例如:

ghc Main.hs -package-db .cabal-sandbox/x86_64-linux-ghc-7.10.2-packages.conf.d/
但是,使用沙盒的“正常”方式是始终使用
cabal build
(或
cabal install
,不带参数)编译,而不是直接运行ghc

  • 运行
    cabalinit
    ,回答问题
  • 编辑生成的
    foo.cabal
    文件(
    foo
    是包的名称)
  • 运行
    cabal build
    cabal install
    -这将为您运行ghc

  • 编辑cabal文件时,请检查导出的模块(如果是lib)是否已列出,以及主src是否正确。还要确保在
    构建依赖项:
    子句中列出了诸如
    自然数等依赖项。

    是否更新了.cabal文件?@Sigrlami恐怕我不明白。我有一个名为
    $HOME/.cabal
    /tmp/haskell-example/.cabal-sandbox
    的目录,但没有
    .cabal
    文件。我需要做什么来更新它?当您在项目中使用命令
    cabalinit
    时,您的项目正在创建
    foo.cabal
    文件,该文件描述了所有需要的依赖项,您需要手动添加它们。假设您的项目名为
    foo
    。例如,请稍等。我想我对阴谋集团的想法是完全错误的。我原以为阴谋集团的沙箱会像VirtualNV或npm环境一样运行,并改变ghc的行为,但看起来唯一的相似之处是它会重定向
    阴谋集团安装
    安装的位置。现在这很有道理。