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 -threaded -i/d/haskell/src --make xxx.hs
开发者_StackOverflow中文版
I understand it uses those files as 'libraries' while compiling but can i do same in GHCi?
I usually import haskell prepackaged lib e.g. import Data.List
or :m +Data.List
.
I tried import /d/haskell/src
-- does not work!
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.
The '-i' flag is fine, the problem is with loading the module.
Within ghci, :m
will only switch to either pre-compiled modules, or modules which were specified on the command-line. You need to use :add MyModule
to tell ghci to compile a Haskell source file.
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
; many, but not all, GHC options can be set that way. Alternatively, you should be able to use it as a parameter directly: ghci -i /d/haskell/src
.
精彩评论