vildric
vildric

Reputation: 950

import qualified in GHCI

Does it is possible to use the equivalent of "import qualified" in GHCI with our OWN module? Something like :m + qualified Data.List which of course doesn't work.

Thanks.

Upvotes: 10

Views: 4406

Answers (2)

Antal Spector-Zabusky
Antal Spector-Zabusky

Reputation: 36612

I don't know of a pretty way to do what you want, but you could fake it with something like this:

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

Every module that GHCi knows about is automatically available fully qualified, 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 multiple files at once, :load can do that too;

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

will work fine. It will put you in the scope of *My.Module1, and then My.Module2My.ModuleN will all be available fully qualified as mentioned above.

For more about GHCi, you can always check the GHC User's Guide, Ch. 2: "Using GHCi"; particularly relevant sections are §2.2, "Loading source files" and §2.4.5, "What's really in scope at the prompt?".

Upvotes: 16

tomferon
tomferon

Reputation: 5001

Just type import qualified Data.Text or import qualified Data.Text as T inside ghci, just as you would do inside your code.

Upvotes: 24

Related Questions