The command (in GHCi)
:load abc
Loads the functions in the file abc (which must exist in the current directory path). How would I load all
It's better if the filenames and the names of the modules will be the same:
➤ mv test1.hs NecessaryModule.hs
➤ ghci
GHCi, version 7.0.4: 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> :load test
[1 of 2] Compiling NecessaryModule ( NecessaryModule.hs, interpreted )
[2 of 2] Compiling Main ( test.hs, interpreted )
Ok, modules loaded: NecessaryModule, Main.
since the :load
command load module(s) (by filenames) and their dependents (as you can read by typing :help
or :?
in the GHCi prompt).
Also the :load
command erase all previous declarations which was defined in the current GHCi session, so for loading all files in the current directory you can do something like this:
Prelude> :q
Leaving GHCi.
➤ ghci *.hs
GHCi, version 7.0.4: 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.
<no location info>:
module `main:NecessaryModule' is defined in multiple files: NecessaryModule.hs
test2.hs
Failed, modules loaded: none.
Prelude> :q
Leaving GHCi.
➤ rm test2.hs
➤ ghci *.hs
GHCi, version 7.0.4: 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.
[1 of 2] Compiling NecessaryModule ( NecessaryModule.hs, interpreted )
[2 of 2] Compiling Main ( test.hs, interpreted )
Ok, modules loaded: NecessaryModule, Main.
*NecessaryModule>
Presumably you mean Haskell source files, because you can't use the :load
command in GHCi for anything else.
At the top of the source file that you load, include the line:
import NecessaryModule
For each of the source files, make sure to name the modules, e.g.,
module NecessaryModule where
should appear. GHCi will automatically link all the files.
If you're trying to import data, take a look at System.Directory
in the documentation.