Skip to content

Importing modules in .ghci file doesn't work

When attempting to import a module in the .ghci file, GHCi does not seem to use the search path.

Define a module names "Macros.hs":

module Macros where

hello :: String -> IO String
hello msg = return ("putStrLn " ++ show msg)

Now, in the same directory, create a .ghci file:

import Macros
:def hello hello

Run GHCi from that same directory, and you get an error:

$ ghci
GHCi, version 7.6.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.

<no location info>:
    Could not find module `Macros'
    It is not a module in the current program, or in any known package.

<interactive>:1:25: Not in scope: `hello'

It seems that GHCi should be able to find "Macros.hs", compile it, and all me to use it in defining macros.

Adding the current directory (relative or absolute) to the search path (using -i) doesn't help.

Why do I want to do this? I want to define GHCi macros in a separate module (that is not related to my program) and import them, rather than defining them directly in the .ghci file.

Trac metadata
Trac field Value
Version 7.6.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component GHCi
Test case
Differential revisions
BlockedBy
Related
Blocking
CC hvr
Operating system
Architecture
Edited by m4dc4p
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information