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?

147pm
  • 2,907
  • 1
  • 18
  • 39

2 Answers2

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
drets
  • 213
  • 1
  • 10
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
mcwitt
  • 111
  • 1