Ram*_*eka 3 haskell ghci ghc-mod
如果我的项目结构如下:
project/
src/
Foo.hs
Bar.hs
Run Code Online (Sandbox Code Playgroud)
使用文件Foo.hs:
module Foo where
foo :: String
foo = "foo"
Run Code Online (Sandbox Code Playgroud)
和Bar.hs:
module Bar where
import Foo
bar :: String
bar = foo ++ "bar"
Run Code Online (Sandbox Code Playgroud)
如果我的当前目录是src,并且我输入ghci并运行:l Bar.hs,我得到预期的输出:
[1 of 2] Compiling Foo ( Foo.hs, interpreted )
[2 of 2] Compiling Bar ( Bar.hs, interpreted )
Ok, modules loaded: Bar, Foo.
Run Code Online (Sandbox Code Playgroud)
但是,如果我移动到project目录(这是我宁愿留下并运行vim/ghci /等),并尝试:l src/Bar.hs,我得到:
src/Bar.hs:3:8:
Could not find module ‘Foo’
Use -v to see a list of the files searched for.
Failed, modules loaded: none.
Run Code Online (Sandbox Code Playgroud)
为什么ghc不会在与Bar相同的目录中搜索Foo?我可以这样做吗?我可以将更改传播到ghc-mod然后传播到ghcmod.vim吗?因为我在vim中运行语法检查程序或ghc-mod类型检查程序时遇到无法找到模块的错误.
我正在运行ghc 7.10.1.
你正在寻找的旗帜是-i<dir>:
% ghci --help
Usage:
ghci [command-line-options-and-input-files]
...
In addition, ghci accepts most of the command-line options that plain
GHC does. Some of the options that are commonly used are:
-i<dir> Search for imported modules in the directory <dir>.
Run Code Online (Sandbox Code Playgroud)
例如
% ls src
Bar.hs Foo.hs
% ghci -isrc
GHCi, version 7.8.2: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
? :l Foo
[1 of 1] Compiling Foo ( src/Foo.hs, interpreted )
Ok, modules loaded: Foo.
? :l Bar
[1 of 2] Compiling Foo ( src/Foo.hs, interpreted )
[2 of 2] Compiling Bar ( src/Bar.hs, interpreted )
Ok, modules loaded: Foo, Bar.
Run Code Online (Sandbox Code Playgroud)
您也可以通过ghc-mod在-i<dir>从内部标志ghcmod.vim
如果您想提供GHC选项,请设置
g:ghcmod_ghc_options.Run Code Online (Sandbox Code Playgroud)let g:ghcmod_ghc_options = ['-idir1', '-idir2']此外,还有缓冲区本地版本
b:ghcmod_ghc_options.Run Code Online (Sandbox Code Playgroud)autocmd BufRead,BufNewFile ~/.xmonad/* call s:add_xmonad_path() function! s:add_xmonad_path() if !exists('b:ghcmod_ghc_options') let b:ghcmod_ghc_options = [] endif call add(b:ghcmod_ghc_options, '-i' . expand('~/.xmonad/lib')) endfunction
| 归档时间: |
|
| 查看次数: |
150 次 |
| 最近记录: |