如何在没有基础的情况下使用cabal repl(ghci)?
以下设计示例显示错误
-- minimal.hs
module Minimal where
myId :: a -> a
myId x = x
和
-- minimal.cabal
name: minimal
version: 0.0.1
build-type: Simple
cabal-version: >= 1.10
library
exposed-modules: Minimal
--build-depends: base
default-language: Haskell2010
default-extensions: NoImplicitPrelude
cabal build成功
$ cabal build
Building minimal-0.0.1...
Preprocessing library minimal-0.0.1...
[1 of 1] Compiling Minimal ( Minimal.hs, dist\build\Minimal.o )
但是cabal repl失败了
$ cabal repl
Preprocessing library minimal-0.0.1...
GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help
<interactive>:1:6: error:
Not in scope: `System.IO.hSetBuffering'
No module named `System.IO' is imported.
<interactive>:1:30: error:
Not in scope: `System.IO.stdin'
No module named `System.IO' is imported.
<interactive>:1:46: error:
Not in scope: data constructor `System.IO.NoBuffering'
No module named `System.IO' is imported.
<interactive>:1:70: error:
Not in scope: `System.IO.hSetBuffering'
No module named `System.IO' is imported.
<interactive>:1:94: error:
Not in scope: `System.IO.stdout'
No module named `System.IO' is imported.
<interactive>:1:111: error:
Not in scope: data constructor `System.IO.NoBuffering'
No module named `System.IO' is imported.
<interactive>:1:135: error:
Not in scope: `System.IO.hSetBuffering'
No module named `System.IO' is imported.
<interactive>:1:159: error:
Not in scope: `System.IO.stderr'
No module named `System.IO' is imported.
<interactive>:1:176: error:
Not in scope: data constructor `System.IO.NoBuffering'
No module named `System.IO' is imported.
如果我恢复“build-depends:base”,如果按预期工作。
$ cabal repl
Preprocessing library minimal-0.0.1...
GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Minimal ( Minimal.hs, interpreted )
Ok, modules loaded: Minimal.
*Minimal>
我知道只要保持“build-depends:base”就能让它发挥作用,但这不是我所要求的。
注意:这也适用于堆栈