6

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?

  • Could it be an indentation problem? Beware of tabs in haskell, use spaces for indentation. – Harald Hanche-Olsen Jun 22 '16 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 '16 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? – Harald Hanche-Olsen Jun 23 '16 at 18:03
8

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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