Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up org-babel for Haskell with Stack

I'm running:

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

I've looked through:

  • Emacs Org-Mode & Literate Haskell
  • https://gist.github.com/reetinder/4022989
  • https://wiki.haskell.org/Emacs/Literate_programming
  • https://wiki.haskell.org/Literate_programming
  • https://github.com/haskell/haskell-mode/issues/1429

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> ?

like image 854
Mittenchops Avatar asked Feb 07 '17 03:02

Mittenchops


2 Answers

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

like image 172
NickD Avatar answered Nov 01 '22 08:11

NickD


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.

like image 2
Testare Avatar answered Nov 01 '22 10:11

Testare