[GHC] #8622: Importing modules in .ghci file doesn't not work

#8622: Importing modules in .ghci file doesn't not work ----------------------------------+--------------------------------- Reporter: m4dc4p | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Keywords: | Operating System: MacOS X Architecture: x86_64 (amd64) | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | ----------------------------------+--------------------------------- 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. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8622 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8622: Importing modules in .ghci file doesn't not work ---------------------------------+---------------------------------- Reporter: m4dc4p | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Resolution: | Keywords: Operating System: MacOS X | Architecture: x86_64 (amd64) Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: ---------------------------------+---------------------------------- Comment (by nomeata): Independent of this possible bug, note that in GHCi you can use symbols without importing them, by using a fully qualified name `Macros.hello`. This works best if you create a Cabal package with Macros and install it. See http://darcs.nomeata.de/ghc-heap-view/ghci for examples. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8622#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8622: Importing modules in .ghci file doesn't work ---------------------------------+---------------------------------- Reporter: m4dc4p | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Resolution: | Keywords: Operating System: MacOS X | Architecture: x86_64 (amd64) Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: ---------------------------------+---------------------------------- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8622#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8622: Importing modules in .ghci file doesn't work ---------------------------------+---------------------------------- Reporter: m4dc4p | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Resolution: | Keywords: Operating System: MacOS X | Architecture: x86_64 (amd64) Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: ---------------------------------+---------------------------------- Comment (by m4dc4p): Replying to [comment:1 nomeata]:
This works best if you create a Cabal package with Macros and install it. See http://darcs.nomeata.de/ghc-heap-view/ghci for examples.
That seems to be the best workaround, but it is a bit of a pain. Thanks for the example! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8622#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8622: Importing modules in .ghci file doesn't work ---------------------------------+---------------------------------- Reporter: m4dc4p | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Resolution: | Keywords: Operating System: MacOS X | Architecture: x86_64 (amd64) Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: ---------------------------------+---------------------------------- Changes (by simonpj): * cc: simonmar (added) Comment: Actually this is by design. You can only use `import` and `:module` for a module that either * is already loaded as part of the current program (`:show modules` tells you which ones are, I think), or * is a module of a visible package If you use `:load Macros` rather than `import Macros`, all is well. However, the [http://www.haskell.org/ghc/docs/latest/html/users_guide /interactive-evaluation.html user documentation] is not good on this point. Notably, it says (2.4.5.1) that "You cannot add a module to the scope if it is not loaded". But that's not true: you can also add (or `import`) any package module. Copying Simon M to check my statements here. If correct, I'll update the documentation. Simion -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8622#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8622: Importing modules in .ghci file doesn't work ---------------------------------+---------------------------------- Reporter: m4dc4p | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Resolution: invalid | Keywords: Operating System: MacOS X | Architecture: x86_64 (amd64) Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: ---------------------------------+---------------------------------- Changes (by m4dc4p): * status: new => closed * resolution: => invalid Comment: Thanks for taking a look - I've marked this bug as invalid, since its by design. Hope that is the right process! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8622#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8622: Importing modules in .ghci file doesn't work ---------------------------------+---------------------------------- Reporter: m4dc4p | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Resolution: invalid | Keywords: Operating System: MacOS X | Architecture: x86_64 (amd64) Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: ---------------------------------+---------------------------------- Comment (by simonmar): Replying to [comment:4 simonpj]:
However, the [http://www.haskell.org/ghc/docs/latest/html/users_guide
/interactive-evaluation.html user documentation] is not good on this point. Notably, it says (2.4.5.1) that "You cannot add a module to the scope if it is not loaded". But that's not true: you can also add (or `import`) any package module.
Copying Simon M to check my statements here. If correct, I'll update
the documentation. Yes, looks like it should say "if it is not loaded or a package module" or something. Maybe the negatives should be reversed. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8622#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8622: Importing modules in .ghci file doesn't work
---------------------------------+----------------------------------
Reporter: m4dc4p | Owner:
Type: bug | Status: closed
Priority: normal | Milestone:
Component: GHCi | Version: 7.6.3
Resolution: invalid | Keywords:
Operating System: MacOS X | Architecture: x86_64 (amd64)
Type of failure: None/Unknown | Difficulty: Unknown
Test Case: | Blocked By:
Blocking: | Related Tickets:
---------------------------------+----------------------------------
Comment (by Simon Peyton Jones

#8622: Importing modules in .ghci file doesn't work ---------------------------------+---------------------------------- Reporter: m4dc4p | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Resolution: invalid | Keywords: Operating System: MacOS X | Architecture: x86_64 (amd64) Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: ---------------------------------+---------------------------------- Comment (by m4dc4p): I'm glad my ticket resulted in such an improvement to the documentation - thank you! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8622#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC