Import to GHCI

Is it possible to use the equivalent β€œimport” in GHCI with our OWN module? Something like :m + qualified Data.List , which of course does not work.

Thanks.

+8
haskell ghci
source share
2 answers

Just type import qualified Data.Text or import qualified Data.Text as T inside ghci, as in your code.

+22
source share

I don't know how to do what you want, but you can fake it like this:

  • First use :load My/Module.hs to load your module.
  • Use :module - My.Module to get it out of scope.
  • (Optional.) Use import qualified My.Module as MM to bring it into scope.

Each module that GHCi knows about is automatically fully accessible, so after step 2 My.Module.value will work fine. Step 3 is only necessary if you want to use a shorter prefix.

If you want to load several files at once :load can do it too

 :load My/Module1.hs My/Module2.hs ... My/ModuleN.hs 

will work fine. It will put you in the *My.Module1 , and then My.Module2 ... My.ModuleN will be fully accessible, as described above.

For more information on GHCi, you can always check the GHC User Guide, chap. 2: "Use of GHCi" ; especially the relevant sections of Β§2.2, "Downloading Source Files" and Β§2.4.5, "What is really in the prompt area?" .

+15
source share

All Articles