Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cabal new-repl only brings one module into scope #5374

Open
mitchellwrosen opened this issue Jun 10, 2018 · 9 comments
Open

cabal new-repl only brings one module into scope #5374

mitchellwrosen opened this issue Jun 10, 2018 · 9 comments

Comments

@mitchellwrosen
Copy link

cabal new-repl and cabal repl only seem to bring one module into scope at the prompt. Is this the intended behavior? Thanks :)

@sjakobi
Copy link
Member

sjakobi commented Aug 4, 2018

Coming from stack repl I found this behaviour surprising too.

@sjakobi
Copy link
Member

sjakobi commented Aug 4, 2018

In particular it's not obvious why only the module that is compiled first is brought into scope, while the other modules are in scope with full qualification.

@hvr
Copy link
Member

hvr commented Aug 4, 2018

Because that's what GHCi does... a related issue is #5103

I don't think there's not much we can do without using some ugly hack like generating some transient .ghci file before and passing that to the ghci session, which then injects ghci commands to modify the startup environment... while making sure that your ~/.ghci or ./.ghci files are honored too and hoping they won't conflict with the autogenerated ghci script... (see also -ghci-script= as documented here )... IOW, not the greatest idea

A better way would be to extend GHCi to fix this in a principled way which lets you explicitly tell GHCi which modules to bring into scope (it's kinda arbitrary as you point out that you get a single module into scope at all), i.e. whether no modules, a single module, all exposed modules, or some user-specified enumerated set (we could even allow wildcards here)

Personally, if I want to setup a particular project-specific default ghci environment I do just that, I create .ghci file which sets up which modules I want in scope by default. Maybe we should document this better in the user's guide.

@sjakobi
Copy link
Member

sjakobi commented Aug 4, 2018

Thanks for the explanation, Herbert!

A better way would be to extend GHCi to fix this in a principled way...

👍

Personally, if I want to setup a particular project-specific default ghci environment I do just that, I create .ghci file which sets up which modules I want in scope by default. Maybe we should document this better in the user's guide.

Also 👍 :)

dnadales added a commit to input-output-hk/cardano-ledger-byron that referenced this issue Dec 24, 2018
Trying to workaround the [limitations in
`ghci`](haskell/cabal#5103) (see also [this
issue](haskell/cabal#5374)) is not worth the time,
specially since a `stack` workflow could be implemented. Additionally, by
explaining the workaround in the README will probably take a lot of effort.
@jberryman
Copy link

Maybe a .ghci file could be created if none exists on project init? Even a blank one with some commented examples might be nice

@mitchellwrosen
Copy link
Author

I have not had success manually crafting a .ghci file to help with this issue. For example, using the .ghci file

:m +MyModule

upon invoking cabal v2-repl, I see

<no location info>: error:
    Could not find module ‘MyModule’
    It is not a module in the current program, or in any known package.

first, followed by e.g.

...
[4 of 8] Compiling MyModule          ( MyModule.hs, interpreted )
...

@jkachmar
Copy link

jkachmar commented Feb 3, 2020

Just wanted to chip-in here, but this is a very frustrating paper-cut that presents itself on a constant basis when developing with cabal v2-repl.

I'd be willing to try and put together a PR based off of however stack handles introspecting upon a given Haskell project to pull out module names to load up when the REPL is booted.

I've tried creating project-specific .ghci files for this purpose, but as @mitchellwrosen notes above it just doesn't work as-expected.

I can understand the reticence to accept a solution that isn't "principled" while the cabal v2-* commands were still in development, but they're on by-default now which means we should have a solution for this.

@phadej
Copy link
Collaborator

phadej commented Feb 3, 2020

As @hvr mentioned, if one wants this to be improved then the ghc --interactive interface needs improvement. I will not accept more hacks into Cabal, we have plenty already.

@prednaz
Copy link

prednaz commented Feb 14, 2022

this also makes ghcid's --allow-eval useless, which is a deal breaker for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants