Hi Thomas, Ihor,
I'm not currently using ob-haskell, but I do have a version of GHC. As
I may use ob-haskell one day, I decided to take a look.
Here are the versions I'm using:
#+begin_src elisp
(list (list "emacs" emacs-version)
(list "org" org-version)
(list "ghc" (string-trim (shell-command-to-string "ghc -V")))
)
#+end_src
#+RESULTS:
| emacs | 29.0.50 |
| org | 9.6-pre |
| ghc | The Glorious Glasgow Haskell Compilation System, version 8.10.7 |
The following code block is incorrect:
#+begin_src haskell :results output
main :: IO ()
main = putStrLn "Hello, World!"
main
#+end_src
#+RESULTS:
: <interactive>:2:1-4: error:
: • Variable not in scope: main :: IO ()
: • Perhaps you meant ‘min’ (imported from Prelude)
: Prelude> Hello, World!
The first line tries to evaluate 'main' which doesn't exist (yet).
The following modified block works, using the compiler.
#+begin_src haskell :compile yes :results output
main :: IO ()
main = putStrLn "Hello, World!"
#+end_src
#+RESULTS:
: Hello, World!
The following works using the interpreter:
#+begin_src haskell
let { main :: IO ()
, main = putStrLn "Hello, World!"
}
main
#+end_src
#+RESULTS:
: Hello, World!
A simpler version, that just print "Hello, World!" works:
#+begin_src haskell
putStrLn "Hello, World!"
#+end_src
#+RESULTS:
: Hello, World!
Just evaluating the string doesn't work!
#+begin_src haskell
"Hello world!"
#+end_src
#+RESULTS:
as we don't get any result ...
If I understand correctly, it seems to be a bug in ob-haskell;
`org-babel-comint-with-output' shouldn't be instructed to remove the
output if it matches the input, else, it will remove any constant.
Adding a type annotation is enough to make it works:
#+begin_src haskell
"Hello world!" :: String
#+end_src
#+RESULTS:
: Hello world!
Or fixing `org-babel-interpret-haskell' (see attached patch):
#+begin_src haskell
"Hello world!"
#+end_src
#+RESULTS:
: Hello world!
Another example that works too, with or without the patch:
#+begin_src haskell
concat ["Hello", ", ", "World", "!"]
#+end_src
#+RESULTS:
: Hello, World!
I've attached the patch that I've used to fix ob-haskell.
Should I submit a patch for ob-haskell ?
Bruno
>From f2e91a62469e84ce1d3036216ae3eca4084f3b94 Mon Sep 17 00:00:00 2001
From: Bruno BARBIER <[email protected]>
Date: Wed, 19 Oct 2022 19:44:42 +0200
Subject: [PATCH] org-babel-interpret-haskell: Don't remove outputs that match
inputs
* lisp/ob-haskell.el (org-babel-interpret-haskell): Change the call to
`org-babel-comint-with-output'.
---
lisp/ob-haskell.el | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lisp/ob-haskell.el b/lisp/ob-haskell.el
index d195dcf87..99e590bfb 100644
--- a/lisp/ob-haskell.el
+++ b/lisp/ob-haskell.el
@@ -136,7 +136,7 @@ (defun org-babel-interpret-haskell (body params)
(comint-preoutput-filter-functions
(cons 'ansi-color-filter-apply comint-preoutput-filter-functions))
(raw (org-babel-comint-with-output
- (session org-babel-haskell-eoe t full-body)
+ (session org-babel-haskell-eoe nil full-body)
(insert (org-trim full-body))
(comint-send-input nil t)
(insert org-babel-haskell-eoe)
--
2.37.3