emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Bruno Barbier <brubar.cs@gmail.com>
To: Ihor Radchenko <yantar92@posteo.net>, "Thomas S. Dye" <tsd@tsdye.online>
Cc: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Re: Haskell code blocks
Date: Wed, 19 Oct 2022 20:03:20 +0200	[thread overview]
Message-ID: <E1olDKk-0001eX-Gq@lists.gnu.org> (raw)
In-Reply-To: <87czaoaziu.fsf@localhost>

[-- Attachment #1: Type: text/plain, Size: 2686 bytes --]


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



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Fix org-babel-interpret-haskell --]
[-- Type: text/x-diff, Size: 1030 bytes --]

From f2e91a62469e84ce1d3036216ae3eca4084f3b94 Mon Sep 17 00:00:00 2001
From: Bruno BARBIER <brubar.cs@gmail.com>
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


  reply	other threads:[~2022-10-19 17:59 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-03  1:16 Haskell code blocks Thomas S. Dye
2022-10-19  2:52 ` Ihor Radchenko
2022-10-19  3:50   ` Thomas S. Dye
2022-10-19  4:22     ` Ihor Radchenko
2022-10-19  4:47       ` Thomas S. Dye
2022-10-19 10:17         ` Ihor Radchenko
2022-10-19 18:03           ` Bruno Barbier [this message]
     [not found]           ` <notmuch-sha1-431220eef964237e131dcf36f817756f3537caf1>
2022-10-21  3:10             ` Ihor Radchenko
2022-11-07  7:24             ` Ihor Radchenko
2022-11-08 18:46               ` Bruno Barbier
2022-11-09  2:54                 ` Ihor Radchenko
2023-03-13 11:38                 ` Ihor Radchenko
2023-03-15 18:12                   ` Bruno Barbier
     [not found]                   ` <notmuch-sha1-86fc4270780c1f4b2624b20be5d3684ddf44d9c0>
2023-03-19  9:20                     ` Bruno Barbier
2022-10-22  5:06 ` Jarmo Hurri

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1olDKk-0001eX-Gq@lists.gnu.org \
    --to=brubar.cs@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=tsd@tsdye.online \
    --cc=yantar92@posteo.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).