Skip to content

stack ghci command is not working #2503

Closed
carliros opened this Issue · 6 comments

2 participants

@carliros

There is an exception when trying to run this command

  $ stack ghci pandoc:exe:pandoc
  Configuring GHCi with the following packages: pandoc
  GHCi, version 7.10.2: http://www.haskell.org/ghc/  :? for help

  <interactive>:1:1:
  attempting to use module ‘Prelude’ (/project path .../pandoc/prelude/Prelude.hs) which is not loaded

Something I am missing ?

@jgm
Owner
jgm commented

I've run across this too -- it's due to pandoc's use of a custom prelude in prelude/Prelude.hs (a recent change to make it easier to support multiple ghc versions).

I've reproduced the problem in the simplest possible way (without using stack or pandoc source). In an empty directory, create two files:

--- Prelude.hs
{-# LANGUAGE PackageImports #-}

module Prelude
(
  module P
, hi
)
where
import "base" Prelude as P
hi = print "hi"
-- test.hs
main = hi

Now ghc --make test.hs works fine. You get a test executable, which produces the output "hi" if you run it.

But ghci test.hs fils with the error

Top level:
    attempting to use module ‘Prelude’ (./Prelude.hs) which is not loaded

It seems to me that this is some kind of bug in ghci, but I'm not sure.

@jgm
Owner
jgm commented

I posted the question here and learned of this bug report against ghci.

There's a workaround: we can add import Prelude to every source file, and add -XNoImplicitPrelude to the ghc-options field in pandoc.cabal. Then both cabal repl and stack ghci will work properly.

@carliros

Thanks for the info John,

you mean to every source file of pandoc? that it is quite a big change for the workaround, or should we wait the bug to be fixed ?
Anyway, I will be happy to do the workaround change if you agree.

@jgm jgm added a commit that closed this issue
@jgm Use -XNoImplicitPrelude and 'import Prelude' explicitly.
This is needed for ghci to work with pandoc, given that we
now use a custom prelude.

Closes #2503.
c423dbb
@jgm jgm closed this in c423dbb
@jgm
Owner
jgm commented

I made the change -- it took about 10 seconds with vim's 'bufdo'.

@carliros

Super.

@jgm
Owner
jgm commented

I've decided to handle this in a different way -- instead of explicitly importing Prelude and using NoImplicitPrelude, we now include the directory containing the custom Prelude only if ghc version is less than 7.10. It compiles on 4 GHC versions, but ghci will only work with ghc 7.10.x. This approach seems cleaner to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.