8

I'm guessing that since Haskell's ghci is not a full-fledged REPL, you can't really use it for defining functions in orgmode source blocks, i.e.,

#+begin_src haskell 
doubleMe x = x + x 
#+end_src

isn't allowed in the ghci. But then

#+begin_src haskell 
let doubleMe x = x + x 
#+end_src

works, but

#+begin_src haskell
let doubleSmallNumber4 x = if x > 0
                            then x 
                             else x*2 
#+end_src

complains about parsing the else. I'm assuming Haskell and orgmode simply don't play well together -- at least when it comes to using orgmode source blocks . . . or am I missing something?

3
  • Could it be an indentation problem? Beware of tabs in haskell, use spaces for indentation. Jun 22, 2016 at 19:23
  • Putting the if statement all on one line works, but multi-line is a no-go in ghci. orgmode simply isn't doing Haskell in the way it does C or Scheme et al.
    – 147pm
    Jun 22, 2016 at 20:44
  • You might need to add :set +m to ~/.ghc/ghci.conf in order to enable multiline input. Or have you done so already? Jun 23, 2016 at 18:03

2 Answers 2

10

You need to enable multi-line commands support in GHCi. Put :set +m to GHCi config file or execute it directly in org-babel session as shown in the following code:

#+begin_src haskell

:set +m

let doubleSmallNumber4 x = if x > 0
                            then x 
                             else x*2 

doubleSmallNumber4 42

#+end_src

#+RESULTS:
: 42
1

Another option for Haskell source blocks in org-mode is to use emacs-jupyter with the IHaskell kernel.

Multi-line code blocks work as expected, e.g.

#+begin_src jupyter-haskell
  let doubleSmallNumber4 x = if x > 0
                              then x 
                               else x*2 

  doubleSmallNumber4 2
#+end_src

#+RESULTS:
: 2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.