简体   繁体   English

使用GHC编译hs文件时的-i选项是什么?如何在GHCi中执行相同的操作?

[英]What is the -i option while compiling hs file using GHC and how to do same in GHCi?

Ok, I've been using the -i compile option to specify the folder to some haskell source when I compile using GHC. 好吧,当我使用GHC编译时,我一直在使用-i编译选项为某些haskell源指定文件夹。

ghc -threaded -i/d/haskell/src --make xxx.hs

I understand it uses those files as 'libraries' while compiling but can i do same in GHCi? 我知道它在编译时会将这些文件用作“库”,但我可以在GHCi中使用它吗?

I usually import haskell prepackaged lib eg import Data.List or :m +Data.List . 我通常导入haskell预先打包的lib,例如import Data.List:m +Data.List

I tried import /d/haskell/src -- does not work! 我试过import /d/haskell/src - 不行!

EDIT From Haskell doc: Chapter 2 Using GHCi Note that in GHCi, and ––make mode, the -i option is used to specify the search path for source files, whereas in standard batch-compilation mode the -i option is used to specify the search path for interface files. 编辑来自Haskell doc: 第2章使用GHCi请注意,在GHCi和––make模式中, -i选项用于指定源文件的搜索路径,而在标准批处理编译模式中, -i选项用于指定接口文件的搜索路径。

The '-i' flag is fine, the problem is with loading the module. '-i'标志很好,问题在于加载模块。

Within ghci, :m will only switch to either pre-compiled modules, or modules which were specified on the command-line. 在ghci中, :m只会切换到预编译模块或命令行中指定的模块。 You need to use :add MyModule to tell ghci to compile a Haskell source file. 你需要使用:add MyModule来告诉ghci编译一个Haskell源文件。

If you have 如果你有

./src/Module/SubModule.hs

you can load it with the following: 您可以使用以下内容加载它:

localuser$ ghci -isrc
GHCi, version 7.0.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude> :add Module.SubModule
[1 of 1] Compiling Module.SubModule        ( src/Module/SubModule.hs, interpreted )
Ok, modules loaded: Module.SubModule.
*Module.SubModule>

I think you can say :set -i /d/haskell/src ; 我想你可以说:set -i /d/haskell/src ; many, but not all, GHC options can be set that way. 许多(但不是全部)GHC选项可以这样设置。 Alternatively, you should be able to use it as a parameter directly: ghci -i /d/haskell/src . 或者,您应该可以直接将其用作参数: ghci -i /d/haskell/src

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM