ghci/堆栈和包可用

ghci / stack and package available

我将 intero 与一些没有项目的文件一起使用,我的全局(或本地 stack.yaml)是:

 ~/.stack/global
$ cat stack.yaml
flags: {}
packages: []
extra-deps: []

resolver: lts-8.21

如果我 stack exec -- ghci:l Intero.hs 其中 Intero.hs 包含:

$ cat Intero.hs
module Intero where

import           Control.Lens.Lens

我得到:

$ stack exec -- ghci
GHCi, version 8.0.2: http://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /Users/nrolland/.emacs.d/.ghci
Prelude
λ> :l Intero.hs
[1 of 1] Compiling Intero           ( Intero.hs, interpreted )

Intero.hs:3:1: error:
    Failed to load interface for ‘Control.Lens.Lens’
    Use -v to see a list of the files searched for.
Failed, modules loaded: none.

我重新启动了 -v:

$ stack exec -- ghci -v
GHCi, version 8.0.2: http://www.haskell.org/ghc/  :? for help
Glasgow Haskell Compiler, Version 8.0.2, stage 2 booted by GHC version 7.10.3
Using binary package database: /Users/nrolland/.stack/programs/x86_64-osx/ghc-8.0.2/lib/ghc-8.0.2/package.conf.d/package.cache
Using binary package database: /Users/nrolland/.stack/snapshots/x86_64-osx/lts-8.23/8.0.2/pkgdb/package.cache
Using binary package database: /Users/nrolland/Sync/clones/haskGist80/.stack-work/install/x86_64-osx/lts-8.23/8.0.2/pkgdb/package.cache
loading package database /Users/nrolland/.stack/programs/x86_64-osx/ghc-8.0.2/lib/ghc-8.0.2/package.conf.d
loading package database /Users/nrolland/.stack/snapshots/x86_64-osx/lts-8.23/8.0.2/pkgdb
loading package database /Users/nrolland/Sync/clones/haskGist80/.stack-work/install/x86_64-osx/lts-8.23/8.0.2/pkgdb
wired-in package ghc-prim mapped to ghc-prim-0.5.0.0

加载 Intero.hs 时,我得到

Intero.hs:3:1: error:
    Failed to load interface for ‘Control.Lens.Lens’
    Locations searched:
      Control/Lens/Lens.hs
      Control/Lens/Lens.lhs
      Control/Lens/Lens.hsig
      Control/Lens/Lens.lhsig
Upsweep partially successful.
*** Deleting temp files:
Deleting:
Failed, modules loaded: none.
loading package database /Users/nrolland/.stack/programs/x86_64-osx/ghc-8.0.2/lib/ghc-8.0.2/package.conf.d
loading package database /Users/nrolland/.stack/snapshots/x86_64-osx/lts-8.23/8.0.2/pkgdb
loading package database /Users/nrolland/Sync/clones/haskGist80/.stack-work/install/x86_64-osx/lts-8.23/8.0.2/pkgdb
wired-in package ghc-prim mapped to ghc-prim-0.5.0.0
wired-in package integer-gmp mapped to integer-gmp-1.0.0.1
wired-in package base mapped to base-4.9.1.0
wired-in package rts mapped to rts-1.0
wired-in package template-haskell mapped to template-haskell-2.11.1.0
wired-in package ghc mapped to ghc-8.0.2
wired-in package dph-seq not found.
wired-in package dph-par not found.

但是 lens 是 lts-8.23 的一部分,虽然我在 ghc-pkg 中查找时我没有看到它

$ stack exec -- ghc-pkg list
/Users/nrolland/.stack/programs/x86_64-osx/ghc-8.0.2/lib/ghc-8.0.2/package.conf.d
    Cabal-1.24.2.0
    array-0.5.1.1
    base-4.9.1.0
    binary-0.8.3.0
    bytestring-0.10.8.1
    containers-0.5.7.1
    deepseq-1.4.2.0
    directory-1.3.0.0
    filepath-1.4.1.1
    ghc-8.0.2
    ghc-boot-8.0.2
    ghc-boot-th-8.0.2
    ghc-prim-0.5.0.0
    ghci-8.0.2
    haskeline-0.7.3.0
    hoopl-3.10.2.1
    hpc-0.6.0.3
    integer-gmp-1.0.0.1
    pretty-1.1.3.3
    process-1.4.3.0
    rts-1.0
    template-haskell-2.11.1.0
    terminfo-0.4.0.2
    time-1.6.0.1
    transformers-0.5.2.0
    unix-2.7.2.1
    xhtml-3000.2.1
/Users/nrolland/.stack/snapshots/x86_64-osx/lts-8.23/8.0.2/pkgdb
    (no packages)
/Users/nrolland/Sync/clones/haskGist80/.stack-work/install/x86_64-osx/lts-8.23/8.0.2/pkgdb
    (no packages)

如何在不创建完整项目的情况下轻松加载模块? 这可能很容易,但我对整个事情的运作方式感到非常困惑..

软件包必须先安装(下载和编译)才能使用:

stack install lens

如果您正在使用 Cabalized 项目(即使对于小事情也是个好主意),stack 将安装您的 cabal 文件中列出的依赖项,因此您不必手动安装它们。

回应您的评论:我认为从技术上讲可以下载并安装所有(某些版本的)stackage,但这似乎不可取。这将花费很长时间,并且与按需安装软件包相比没有什么好处。此外,我不知道有什么自动化的方法可以做到这一点。我知道在 "offline hackage" 存储方面已经完成了一些有趣的工作,但还没有准备好使用。