[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Haskell code blocks
From: |
Bruno Barbier |
Subject: |
Re: Haskell code blocks |
Date: |
Wed, 19 Oct 2022 20:03:20 +0200 |
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
0001-org-babel-interpret-haskell-Don-t-remove-outputs-tha.patch
Description: Fix org-babel-interpret-haskell