haskellemacsread-eval-print-loophaskell-mode

haskell repl in emacs


Hi i am starting with haskell and trying to set up my emacs for its development.

I have haskell-mod and ghc-mod latest in emacs 24.3.1. GHC is 7.6.3

i have created a haskell file first.hs and when i do C-c C-l It asks :

start a new project named haskell ? y or n

my directory name is haskell. I press y

Set the cabal directory

I have tried with both ~/.cabal and my current directory named haskell

Set the current directory

Just pressed enter as it has haskell directory

It shows error messages :

haskell-process-start: cl-ecase failed: cabal-rep, (ghci quote cabal-repl quote cabal-ghci quote cabal-dev quote)

How can i get the repl ?

I read that i may need to downgrad the ghc version to make it work. Is that good solution ?

Solution :

I had multiple custom-set-variables in init.el and it led to the problem.


Solution

  • UPDATE 2017

    now that we have Intero I would suggest you try Intero/Stack - it works rather well.

    With it my config is slimmed even more down:

    ;; ----------------------------------------------------------------------
    ;; HASKELL
    (require 'haskell-mode)
    (require 'intero)
    (add-hook 'haskell-mode-hook 'intero-mode)
    (require 'flycheck)
    (setq flycheck-check-syntax-automatically '(save new-line))
    (flycheck-add-next-checker 'intero '(warning . haskell-hlint))
    

    Concerning the REPL you basically just load the file and then C-c C-l into the repl (you can always switch between the two windows with C-c C-z and you can clear out the repl-buffer with C-c C-k (when inside).

    The only drawback is that Intero is usually installed locally in your project, so the first startup into a new project will take a while for Intero to download/compile/boot-up - but it's no big deal and you gain much.


    UPDATE

    Now that stack is out and running great I would recommend setting the haskell-process-type to auto and maybe installing ghc-mod using stack.

    here is the current setup I am using:

    (require 'haskell-mode)
    (add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode)
    (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
    (add-hook 'haskell-mode-hook 'linum-mode)
    (add-to-list 'exec-path "~/.local/bin")
    (eval-after-load 'haskell-mode '(progn
      (define-key haskell-mode-map (kbd "C-c C-l") 'haskell-process-load-file)
      (define-key haskell-mode-map (kbd "C-c C-n C-t") 'haskell-process-do-type)
      (define-key haskell-mode-map (kbd "C-c C-n C-i") 'haskell-process-do-info)
      (define-key haskell-mode-map "\C-ch" 'haskell-hoogle)))
    (eval-after-load 'haskell-cabal '(progn
      (define-key haskell-cabal-mode-map (kbd "C-c C-k") 'haskell-interactive-ode-clear)
      (define-key haskell-cabal-mode-map (kbd "C-c C-c") 'haskell-process-cabal-build)
      (define-key haskell-cabal-mode-map (kbd "C-c c") 'haskell-process-cabal)))
    
    (require 'company-ghci)
    (push 'company-ghci company-backends)
    (add-hook 'haskell-mode-hook 'company-mode)
    (add-hook 'haskell-interactive-mode-hook 'company-mode)
    

    As you can see I basically got rid of all ghc-mod related stuff (stack works as is with the current haskell-mode) and replaced the company backend (although this one is really slow and I hope to find something better)

    variables

    Theses you usually set within Emacs/Configuration of Haskell-Mode

    (custom-set-variables
     ;; there is of course more in here - these are the Haskell related:
     '(haskell-font-lock-symbols (quote unicode))
     '(haskell-hoogle-command nil)
     '(haskell-mode-hook
       (quote
        (linum-mode turn-on-haskell-indentation turn-on-haskell-doc-mode)) t)
     '(haskell-process-auto-import-loaded-modules t)
     '(haskell-process-load-or-reload-prompt t)
     '(haskell-process-log t)
     '(haskell-process-suggest-language-pragmas nil)
     '(haskell-process-suggest-no-warn-orphans t)
     '(haskell-process-type (quote auto))
     '(haskell-process-use-presentation-mode t)
     '(haskell-tags-on-save t)
     '(inferior-haskell-wait-and-jump t)
     '(safe-local-variable-values
       (quote
        ((haskell-process-use-ghci . t)
         (haskell-indent-spaces . 4))))
     (uniquify)))
    

    These are the packages I added:


    First

    if it asks for your cabal directory - it wants to know where your myProject.cabal file is - if you don't have one just take the folder where your file is (the default - I think the default/find never failed me till now).

    in case you need some sample-.emacs-setup

    Here are parts from my .emacs file that works for me:

    (autoload 'ghc-init "ghc" nil t)
    (autoload 'ghc-debug "ghc" nil t)
    (add-hook 'haskell-mode-hook (lambda () (ghc-init)))
    (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
    
    (eval-after-load 'haskell-mode '(progn
      (define-key haskell-mode-map (kbd "C-c C-l") 'haskell-process-load-or-reload)
      (define-key haskell-mode-map (kbd "C-`") 'haskell-interactive-bring)
      (define-key haskell-mode-map (kbd "C-c C-n C-t") 'haskell-process-do-type)
      (define-key haskell-mode-map (kbd "C-c C-n C-i") 'haskell-process-do-info)
      (define-key haskell-mode-map (kbd "C-c C-n C-c") 'haskell-process-cabal-build)
      (define-key haskell-mode-map (kbd "C-c C-n c") 'haskell-process-cabal)))
    (eval-after-load 'haskell-cabal '(progn
      (define-key haskell-cabal-mode-map (kbd "C-`") 'haskell-interactive-bring)
      (define-key haskell-cabal-mode-map (kbd "C-c C-k") 'haskell-interactive-ode-clear)
      (define-key haskell-cabal-mode-map (kbd "C-c C-c") 'haskell-process-cabal-build)
      (define-key haskell-cabal-mode-map (kbd "C-c c") 'haskell-process-cabal)))
    
    (custom-set-variables
     '(haskell-interactive-mode-hide-multi-line-errors nil)
     '(haskell-process-log t)
     '(haskell-process-type (quote cabal-repl)))
    

    Please note the part with (quote cabal-repl) - this should work with cabal sandboxes. Also this will add more logging information to a buffer named haskell-process-log where you might find more about your problem.

    I use this with ghc-mod version 5.1.0.2 compiled by GHC 7.8.3 and GHC 7.8.3 obviously.

    Of course you have to make sure that your .cabal folder and the place where ghc-mod is in your path (I think you can configure this somewhere in the emacs settings too - but it's much easier this way).

    remarks

    further information

    If this does not help you please feel free to

    sample run on my machine

    I edited a sample file like this:

    Helo Emacs

    Then I hit C-c C-l and press y:

    Step 2

    And accept the folder (this is where the file is located) and any other questions with Ret - now you should see the *haskell* buffer with a friendly message/lambda:

    Step 3

    Finally I can check that the file got loaded:

    enter image description here