19

I'm running:

  • GNU Emacs 24.4.1
  • Stack Version 1.3.3
  • org-mode
  • haskell-mode

I've looked through:

While the gist above looks promising, I haven't found anything that looked to be an authoritative way to get org-haskell running (eg, nothing on melpa), and certainly nothing aimed specifically at whatever intricacy running a stack environment rather than using my global ghc would entail.

When I try to:

#+BEGIN_SRC haskell
let x = "test"
putStrLn x
#+END_SRC

I get

executing Haskell code-block

...which hangs forever. When I C-g, I see:

GHCi, version 7.6.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Some flags have not been recognized: prompt2, ghci     | 
ghci    λ> let x = "TESTING!"
putStrLn x
"org-babel-haskell-eoe"
Prelude| 
<interactive>:4:1: parse error on input `putStrLn'
ghci    λ> "org-babel-haskell-eoe"

When I tab to the haskell buffer, I see it has genuinely evaluated what I sent, it just has this org-babel-haskell-eoe error and never returns control to my org session.

Any chance this is because I have a custom prompt? Using the lambda instead of Prelude> ?

Community
  • 1
  • 1
Mittenchops
  • 18,633
  • 33
  • 128
  • 246
  • You might find this other question useful: http://stackoverflow.com/questions/42081379/how-to-set-up-org-babel-for-haskell-with-stack – brittAnderson Feb 07 '17 at 13:48
  • You need to load `ob-haskell.el` (or add haskell to `org-babel-load-languages` and restart emacs) before you can try evaluating haskell code blocks. That should get rid of the "No org-babel-execute function for haskell" message at least. – NickD Feb 07 '17 at 17:09
  • 1
    @brittUWaterloo, I believe you linked to this very question of mine. – Mittenchops Feb 08 '17 at 04:33
  • @Nick, ob-haskell.el from where? – Mittenchops Feb 08 '17 at 04:33
  • It's part of "official" org-mode: you should be able to just say `(require 'ob-haskell)` and get it loaded. But I'm not sure whether it is going to help with anything other than that initial problem, which you might (or might not) have gotten past by now. – NickD Feb 08 '17 at 17:04
  • Thanks, @Nick. Yep, you're right, I loaded that and same hanging message. – Mittenchops Feb 11 '17 at 04:41
  • "org-babel-haskell-eoe" is a marker that ob-haskell uses to separate the results from the rest of the interpreter output, so that it can cut out the chaff and present the results in the org-mode buffer. – NickD Feb 17 '17 at 16:22

4 Answers4

6

This is not a complete answer: in particular, it does not even mention Stack. But I (a complete ignoramus on Haskell) wanted to find out what it would take to get the OP's test program to run in babel. Here's what I found:

  • You need a haskell interpreter ;-) I'm on Fedora 24, so I installed the ghc-compiler package and I got ghci.

  • You need haskell-mode. I installed that from MELPA, using the emacs package manager. That also installed inf-haskell.el

  • By default, inf-haskell wants to run hugs, so I customized haskell-program-name and set it to "ghci".

  • M-x load-library RET ob-haskell RET

  • C-c C-c on the code block: the first time it fails and the Messages buffer shows "Buffer haskell.org does not exist or has no process".

  • But if you do it C-c C-c on the code block again, it succeeds!

Obviously, ob-haskell.el needs some work - and that's before we even get to Stack, of which I know even less than I know of Haskell, so I'll leave that as an exercise for the interested reader :-)

EDIT: Re. version info (requested in a comment): I keep close to the bleeding edge. At this point in time (2017-05-01), I run Org mode version 9.0.5 (release_9.0.5-444-g998576 @ /home/nick/elisp/org-mode/lisp/) and GNU Emacs 26.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.20.10) of 2017-04-14

NickD
  • 5,937
  • 1
  • 21
  • 38
2

It is probably because of the custom prompt: I had the same issue, and when I removed ":set +t" and ":set prompt "GHCI >" from ~/.ghci, it worked. I fiddled with it some, and it seems it will work so long as your custom prompt doesn't have any spaces in it except the end (I changes mine to "GHCI> " and it works). It seems to be that the regular expression it parses the information from assumes the prompt will have no spaces in it.

Testare
  • 338
  • 3
  • 12
2

In my case it was .ghci, like Testare's. As soon as I commented out :set prompt "λ ", emacs stopped freezing but gave the message ‘org-babel-script-escape’ expects a string. It was necessary to comment out :set +t for it to work.

appomsk
  • 143
  • 4
  • I'm at the stage of seeing `org-bable-script escape expects a string`, but it's unclear from the docs of that function why that would be occurring. – Colin Woodbury Jun 26 '21 at 16:48
  • `:set prompt "> "` works best. The `> ` is embedded in the regexp somewhere in ob-haskell.el. – tony day Sep 16 '21 at 06:06
1

what i did after installed stack and ghci (with stack itself)), was to install intero in emacs and then add those to init.el:

 (setq haskell-process-type 'stack-ghci)
 ((org-babel-do-load-languages
     'org-babel-load-languages
        '((haskell . t)))

after that i can C-c C-c in haskell code block and i get a result under the code block.

Azriel
  • 407
  • 2
  • 9