Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In emacs stack-ghci cannot load interface files but `stack build` from the command line does

I can stack build a project from the command line but when I try C-c C-l in emacs (with (custom-set-variables '(haskell-process-type 'stack-ghci))) I get an error that all the package modules I import can't be found.

/home/amcp011/bec/amcp011/accelerate/gpe/src/Numeric/GPE/Utils.hs:30:1: error:
    Failed to load interface for ‘Data.Array.Accelerate’
    Locations searched:
      Data/Array/Accelerate.hs
      Data/Array/Accelerate.lhs
      Data/Array/Accelerate.hsig
      Data/Array/Accelerate.lhsig
      /home/amcp011/bec/amcp011/accelerate/gpe/src/Data/Array/Accelerate.hs
      /home/amcp011/bec/amcp011/accelerate/gpe/src/Data/Array/Accelerate.lhs
      /home/amcp011/bec/amcp011/accelerate/gpe/src/Data/Array/Accelerate.hsig
      /home/amcp011/bec/amcp011/accelerate/gpe/src/Data/Array/Accelerate.lhsig

gpe.cabal:

build-depends:       base >= 4.7 && < 5
                   , bytestring
                   , bytestring-conversion
                   , mtl
                   , time
                   , filepath
                   , directory
                   , accelerate
                   , accelerate-io

stack.yaml:

extra-deps: [accelerate-1.0.0.0
            ,accelerate-io-1.0.0.0
            ]
like image 209
vivian Avatar asked Aug 14 '17 23:08

vivian


People also ask

How do I load a Haskell file into Ghci?

Open a command window and navigate to the directory where you want to keep your Haskell source files. Run Haskell by typing ghci or ghci MyFile. hs. (The "i" in "GHCi" stands for "interactive", as opposed to compiling and producing an executable file.)

What is stack Ghci?

stack ghci allows you to load components and files of your project into ghci . It uses the same TARGET syntax as stack build , and can also take options like --test , --bench , and --flag . Similarly to stack build , the default is to load up ghci with all libraries and executables in the project.

How does GHCi work?

GHCi actually accepts statements rather than just expressions at the prompt. This means you can bind values and functions to names, and use them in future expressions or statements. The syntax of a statement accepted at the GHCi prompt is exactly the same as the syntax of a statement in a Haskell do expression.


1 Answers

I was able to compile your project with stack build (of course, after installing a few system wide dependencies like llvm, cuda, fftw3 etc.) and load it fine with C-c C-l in emacs.

Here is the minimal emacs config that worked for me:

(defun haskell-mode-setup ()
  (setq haskell-process-type 'stack-ghci))

(add-hook 'haskell-mode-hook 'interactive-haskell-mode)
(add-hook 'haskell-mode-hook 'haskell-mode-setup)

The only ways I was able to replicate the issue you are having was with inf-haskell-mode, instead of interactive-haskell-mode, as well as simply by setting (setq haskell-process-type 'ghci). So, it is possible that emacs doesn't find stack.

I'd recommend trying to let haskell-mode know where stack is, in case that it is installed in a non-common location: (setq haskell-process-path-stack "/path/to/stack").

Alternatively, I've solved a few issues in the past related to $PATH environment variable being not the same that is set for the current user, but the one that is used system wide. Simply install exec-path-from-shell emacs package and add (exec-path-from-shell-initialize) to the ~/.emacs.

Also, if you haven't done it yet, inspecting haskell-mode log could prove being useful. Add (setq haskell-process-log t) to haskell-mode-setup, which will result in an extra buffer with the log.

Notes:

  • In order to compile your package, I had to remove few lines from stack.yaml, namely ones that include local dirs /home/amcp011/local/, which are not included in the repo and use my system installed gcc instead of one from RHEL6.3.
  • If you use some other emacs packages besides haskell-mode, they might be the cause of the problem as well. I've tested it with intero and flycheck without any problems.
  • Try upgrading to newest stack upgrade and haskell-mode, maybe that will help. I've tested with stack-1.5.1 and haskell-mode-20170824.1124 on emacs-25.2.2
like image 66
lehins Avatar answered Oct 31 '22 17:10

lehins