haskell / haskell/cabal

Weird behaviour with loading custom GHCI config

Open
#7,789 3 comments 0 reactions 0 assignees View on GitHub
cabal-install: cmd/repl type: bug
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

This is with cabal-install 3.6.2.0, GHC 8.10.7, Manjaro Linux.

I have the following in my `~/.ghc/ghci.conf`:
```
:add /home/gthomas/.ghc/ghci.hs
:set -interactive-print ghciInteractivePrint
:set prompt-function ghciPromptFunction
```

And in `~/.ghc/ghci.hs` (obviously this isn't my real config, it's much simplified):
```
ghciInteractivePrint :: Show a => a -> IO ()
ghciInteractivePrint x = putStrLn "printing..."

ghciPromptFunction :: [String] -> Int -> IO String
ghciPromptFunction modules _lineno = pure "prompt> "
```

In plain `ghci`, everything works as expected:
```
GHCi, version 8.10.7: https://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Main ( /home/gthomas/.ghc/ghci.hs, interpreted )
Ok, one module loaded.
Loaded GHCi configuration from /home/gthomas/.ghc/ghci.conf
prompt> 1
printing...
prompt>
```

Running `cabal repl` within a cabal project directory, somehow `ghciPromptFunction` is loaded but not `ghciInteractivePrint`:
```
Build profile: -w ghc-8.10.7 -O1
In order, the following will be built (use -v for more details):
- hello-hs-0.1.0.0 (exe:hello-hs) (file app/Main.hs changed)
Preprocessing executable 'hello-hs' for hello-hs-0.1.0.0..
GHCi, version 8.10.7: https://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Main ( /home/gthomas/.ghc/ghci.hs, interpreted )
Ok, one module loaded.
Loaded GHCi configuration from /home/gthomas/.ghc/ghci.conf
[1 of 1] Compiling Main ( app/Main.hs, interpreted )
Ok, one module loaded.
prompt> 1
1
prompt>
```

Running `cabal repl` outside of a project directory, everything fails to load, but there are at least visible errors (possibly only due to `setcwd.ghci`, which I can't find any mention of anywhere - what's the purpose of it?):
```
Resolving dependencies...
Build profile: -w ghc-8.10.7 -O1
In order, the following will be built (use -v for more details):
- fake-package-0 (lib) (first run)
Configuring library for fake-package-0..
Preprocessing library for fake-package-0..
Warning: No exposed modules
GHCi, version 8.10.7: https://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Main ( /home/gthomas/.ghc/ghci.hs, interpreted )
Ok, one module loaded.

:1:1: error: Not in scope: ‘ghciInteractivePrint’

:1:2: error:
Variable not in scope:
ghciPromptFunction :: [String] -> Int -> IO String
Loaded GHCi configuration from /home/gthomas/.ghc/ghci.conf
Warning: changing directory causes all loaded modules to be unloaded,
because the search path has changed.
Loaded GHCi configuration from /tmp/cabal-repl.-171000/setcwd.ghci
Prelude> 1
1
Prelude>
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.