emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Fwd: Support compilation of Haskell in org mode babel blocks.
       [not found] <CAMdauZqv91_bW2aZj=AT32vBdyPia92vjeVFMmsFazsEhJCTHg@mail.gmail.com>
@ 2020-04-28 14:56 ` Roland Coeurjoly
  2020-05-04 15:26   ` Nicolas Goaziou
  2020-05-04 15:29   ` Nicolas Goaziou
  0 siblings, 2 replies; 20+ messages in thread
From: Roland Coeurjoly @ 2020-04-28 14:56 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 1024 bytes --]

---------- Forwarded message ---------
From: Roland Coeurjoly <rolandcoeurjoly@gmail.com>
Date: Sat, Apr 25, 2020 at 9:04 PM
Subject: Support compilation of Haskell in org mode babel blocks.
To: <bug-gnu-emacs@gnu.org>


Haskell code can be both compiled (for example with ghc), or interpreted
(with ghci).

Until now, org babel had only support for interpretation.

Haskell is weird in that some code for the interpreter cannot be compiled
and viceversa.
For example, in ghci (the interpreter) you are required to use let to
declare functions
<https://stackoverflow.com/questions/28927716/org-babel-for-haskell-not-works-of-eval-haskell-block/40920873>
.

In this patch I add support for compilation with the header argument
:compile yes.
The function to compile haskell is almost a copy paste of the C funcion in
ob-C.el.

By default I retain the original behavior, i.e. interpreting the block.

I have tested this patch in emacs-27.0.91.


It is my first patch to GNU Emacs and I am a newbie with both elisp and
haskell.

[-- Attachment #1.2: Type: text/html, Size: 1570 bytes --]

[-- Attachment #2: 0001-Add-Haskell-specific-header-argument-compile-to-comp.patch --]
[-- Type: text/x-patch, Size: 4607 bytes --]

From 091f470a278561a60fac1ee3ee658f6823bc2503 Mon Sep 17 00:00:00 2001
From: Roland Coeurjoly <rolandcoeurjoly@gmail.com>
Date: Sat, 25 Apr 2020 20:35:22 +0200
Subject: [PATCH] Add Haskell specific header argument compile, to compile
 instead of interpret the body of source block

---
 lisp/org/ob-haskell.el | 76 +++++++++++++++++++++++++++++++++++++++---
 1 file changed, 71 insertions(+), 5 deletions(-)

diff --git a/lisp/org/ob-haskell.el b/lisp/org/ob-haskell.el
index e004a3405e..d32a2f7bc0 100644
--- a/lisp/org/ob-haskell.el
+++ b/lisp/org/ob-haskell.el
@@ -23,12 +23,13 @@
 
 ;;; Commentary:
 
-;; Org-Babel support for evaluating haskell source code.  This one will
-;; be sort of tricky because haskell programs must be compiled before
+;; Org-Babel support for evaluating Haskell source code.
+;; Haskell programs must be compiled before
 ;; they can be run, but haskell code can also be run through an
 ;; interactive interpreter.
 ;;
-;; For now lets only allow evaluation using the haskell interpreter.
+;; By default we evaluate using the Haskell interpreter.
+;; To use the compiler, specify :compile yes in the header.
 
 ;;; Requirements:
 
@@ -47,6 +48,7 @@
 (declare-function run-haskell "ext:inf-haskell" (&optional arg))
 (declare-function inferior-haskell-load-file
 		  "ext:inf-haskell" (&optional reload))
+(declare-function org-entry-get "org" (pom property &optional inherit literal-nil))
 
 (defvar org-babel-tangle-lang-exts)
 (add-to-list 'org-babel-tangle-lang-exts '("haskell" . "hs"))
@@ -60,8 +62,64 @@ org-babel-haskell-eoe
 
 (defvar haskell-prompt-regexp)
 
-(defun org-babel-execute:haskell (body params)
-  "Execute a block of Haskell code."
+(defcustom org-babel-Haskell-compiler "ghc"
+  "Command used to compile a Haskell source code file into an executable.
+May be either a command in the path, like ghc
+or an absolute path name, like /usr/local/bin/ghc
+parameter may be used, like ghc -v"
+  :group 'org-babel
+  :version "27.0"
+  :type 'string)
+
+(defconst org-babel-header-args:haskell '((compile . :any))
+  "Haskell-specific header arguments.")
+
+(defun org-babel-Haskell-execute (body params)
+  "This function should only be called by `org-babel-execute:haskell'"
+  (let* ((tmp-src-file (org-babel-temp-file
+			"Haskell-src-"
+                        ".hs"))
+         (tmp-bin-file
+          (org-babel-process-file-name
+           (org-babel-temp-file "Haskell-bin-" org-babel-exeext)))
+         (cmdline (cdr (assq :cmdline params)))
+         (cmdline (if cmdline (concat " " cmdline) ""))
+         (flags (cdr (assq :flags params)))
+         (flags (mapconcat 'identity
+		           (if (listp flags) flags (list flags)) " "))
+         (libs (org-babel-read
+	        (or (cdr (assq :libs params))
+	            (org-entry-get nil "libs" t))
+	        nil))
+         (libs (mapconcat #'identity
+		          (if (listp libs) libs (list libs))
+		          " ")))
+    (with-temp-file tmp-src-file (insert body))
+    (org-babel-eval
+     (format "%s -o %s %s %s %s"
+             org-babel-Haskell-compiler
+	     tmp-bin-file
+	     flags
+	     (org-babel-process-file-name tmp-src-file)
+	     libs) "")
+    (let ((results
+	   (org-babel-eval
+	    (concat tmp-bin-file cmdline) "")))
+      (when results
+        (setq results (org-trim (org-remove-indentation results)))
+        (org-babel-reassemble-table
+         (org-babel-result-cond (cdr (assq :result-params params))
+	   (org-babel-read results t)
+	   (let ((tmp-file (org-babel-temp-file "Haskell-")))
+	     (with-temp-file tmp-file (insert results))
+	     (org-babel-import-elisp-from-file tmp-file)))
+         (org-babel-pick-name
+	  (cdr (assq :colname-names params)) (cdr (assq :colnames params)))
+         (org-babel-pick-name
+	  (cdr (assq :rowname-names params)) (cdr (assq :rownames params)))))
+      )))
+
+(defun org-babel-interpret-Haskell (body params)
   (require 'inf-haskell)
   (add-hook 'inferior-haskell-hook
             (lambda ()
@@ -96,6 +154,14 @@ org-babel-execute:haskell
      (org-babel-pick-name (cdr (assq :rowname-names params))
 			  (cdr (assq :rowname-names params))))))
 
+
+(defun org-babel-execute:haskell (body params)
+  "Execute a block of Haskell code."
+  (setq compile (string= (cdr (assq :compile params)) "yes"))
+  (if (not compile)
+      (org-babel-interpret-Haskell body params)
+    (org-babel-Haskell-execute body params)))
+
 (defun org-babel-haskell-initiate-session (&optional _session _params)
   "Initiate a haskell session.
 If there is not a current inferior-process-buffer in SESSION
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: Fwd: Support compilation of Haskell in org mode babel blocks.
  2020-04-28 14:56 ` Fwd: Support compilation of Haskell in org mode babel blocks Roland Coeurjoly
@ 2020-05-04 15:26   ` Nicolas Goaziou
  2020-05-04 16:39     ` Roland Coeurjoly
  2020-05-04 15:29   ` Nicolas Goaziou
  1 sibling, 1 reply; 20+ messages in thread
From: Nicolas Goaziou @ 2020-05-04 15:26 UTC (permalink / raw)
  To: Roland Coeurjoly; +Cc: emacs-orgmode

Hello,

Roland Coeurjoly <rolandcoeurjoly@gmail.com> writes:

> From 091f470a278561a60fac1ee3ee658f6823bc2503 Mon Sep 17 00:00:00 2001
> From: Roland Coeurjoly <rolandcoeurjoly@gmail.com>
> Date: Sat, 25 Apr 2020 20:35:22 +0200
> Subject: [PATCH] Add Haskell specific header argument compile, to compile
>  instead of interpret the body of source block

Thank you!

Could you rewrite the commit message so that it is on par with our
conventions?

It could be something like:

  ob-haskell: introduce :compile header argument

  * lisp/ob-haskell (org-babel-haskell-compiler):
  (org-babel-header-args:haskell): new variables.
  (org-babel-haskell-execute):
  (org-babel-haskell-interpret): new functions.
  (org-babel-execute:haskell): use new functions.

> -;; Org-Babel support for evaluating haskell source code.  This one will
> -;; be sort of tricky because haskell programs must be compiled before
> +;; Org-Babel support for evaluating Haskell source code.
> +;; Haskell programs must be compiled before

"Org Babel" would be even better, while you're changing this line.

> +(defcustom org-babel-Haskell-compiler "ghc"

No need to capitalize Haskell here.

> +  "Command used to compile a Haskell source code file into an executable.
> +May be either a command in the path, like ghc

like "ghc"

> +or an absolute path name, like /usr/local/bin/ghc

like "/usr/local/bin/ghc".

> +parameter may be used, like ghc -v"

The command can include a parameter, such as "ghc -v".

> +  :group 'org-babel
> +  :version "27.0"

It should be :package-version '(Org "9.4") instead.

> +  :type 'string)
> +
> +(defconst org-babel-header-args:haskell '((compile . :any))
> +  "Haskell-specific header arguments.")
> +
> +(defun org-babel-Haskell-execute (body params)
> +  "This function should only be called by `org-babel-execute:haskell'"
> +  (let* ((tmp-src-file (org-babel-temp-file
> +			"Haskell-src-"
> +                        ".hs"))

Indentation seems a bit off.

> +         (tmp-bin-file
> +          (org-babel-process-file-name
> +           (org-babel-temp-file "Haskell-bin-" org-babel-exeext)))
> +         (cmdline (cdr (assq :cmdline params)))
> +         (cmdline (if cmdline (concat " " cmdline) ""))
> +         (flags (cdr (assq :flags params)))
> +         (flags (mapconcat 'identity

Nitpick: #'identity

> +		           (if (listp flags) flags (list flags)) " "))
> +         (libs (org-babel-read
> +	        (or (cdr (assq :libs params))
> +	            (org-entry-get nil "libs" t))
> +	        nil))

Ditto, mind the indentation.

> +         (libs (mapconcat #'identity
> +		          (if (listp libs) libs (list libs))
> +		          " ")))
> +    (with-temp-file tmp-src-file (insert body))
> +    (org-babel-eval
> +     (format "%s -o %s %s %s %s"
> +             org-babel-Haskell-compiler
> +	     tmp-bin-file
> +	     flags
> +	     (org-babel-process-file-name tmp-src-file)
> +	     libs) "")

Please move the empty string below.

> +    (let ((results
> +	   (org-babel-eval
> +	    (concat tmp-bin-file cmdline) "")))
> +      (when results
> +        (setq results (org-trim (org-remove-indentation results)))
> +        (org-babel-reassemble-table
> +         (org-babel-result-cond (cdr (assq :result-params params))
> +	   (org-babel-read results t)
> +	   (let ((tmp-file (org-babel-temp-file "Haskell-")))
> +	     (with-temp-file tmp-file (insert results))
> +	     (org-babel-import-elisp-from-file tmp-file)))
> +         (org-babel-pick-name
> +	  (cdr (assq :colname-names params)) (cdr (assq :colnames params)))
> +         (org-babel-pick-name
> +	  (cdr (assq :rowname-names params)) (cdr (assq :rownames params)))))
> +      )))

Please move the closing parens on the line above.
> +
> +(defun org-babel-interpret-Haskell (body params)

Why capitalization in function names?

>    (require 'inf-haskell)
>    (add-hook 'inferior-haskell-hook
>              (lambda ()
> @@ -96,6 +154,14 @@ org-babel-execute:haskell
>       (org-babel-pick-name (cdr (assq :rowname-names params))
>  			  (cdr (assq :rowname-names params))))))
>  
> +
> +(defun org-babel-execute:haskell (body params)
> +  "Execute a block of Haskell code."
> +  (setq compile (string= (cdr (assq :compile params)) "yes"))

Use a let-binding instead of setq.


Could you send an updated patch?

Regards,

-- 
Nicolas Goaziou


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Fwd: Support compilation of Haskell in org mode babel blocks.
  2020-04-28 14:56 ` Fwd: Support compilation of Haskell in org mode babel blocks Roland Coeurjoly
  2020-05-04 15:26   ` Nicolas Goaziou
@ 2020-05-04 15:29   ` Nicolas Goaziou
  2020-05-04 15:42     ` Roland Coeurjoly
  1 sibling, 1 reply; 20+ messages in thread
From: Nicolas Goaziou @ 2020-05-04 15:29 UTC (permalink / raw)
  To: Roland Coeurjoly; +Cc: emacs-orgmode

Roland Coeurjoly <rolandcoeurjoly@gmail.com> writes:

>  lisp/org/ob-haskell.el | 76 +++++++++++++++++++++++++++++++++++++++---
>  1 file changed, 71 insertions(+), 5 deletions(-)

I forgot to say a change of this size requires you to sign FSF papers.
Please consider doing so if that's not already the case.

Thank you.


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Fwd: Support compilation of Haskell in org mode babel blocks.
  2020-05-04 15:29   ` Nicolas Goaziou
@ 2020-05-04 15:42     ` Roland Coeurjoly
  2020-05-04 21:52       ` Nicolas Goaziou
  0 siblings, 1 reply; 20+ messages in thread
From: Roland Coeurjoly @ 2020-05-04 15:42 UTC (permalink / raw)
  To: Roland Coeurjoly, emacs-orgmode

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

I have read the page about signing FSF papers, but I am unclear about how
to proceed.
Could you give some pointers?
Thank you.

On Mon, May 4, 2020 at 5:29 PM Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:

> Roland Coeurjoly <rolandcoeurjoly@gmail.com> writes:
>
> >  lisp/org/ob-haskell.el | 76 +++++++++++++++++++++++++++++++++++++++---
> >  1 file changed, 71 insertions(+), 5 deletions(-)
>
> I forgot to say a change of this size requires you to sign FSF papers.
> Please consider doing so if that's not already the case.
>
> Thank you.
>

[-- Attachment #2: Type: text/html, Size: 968 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Fwd: Support compilation of Haskell in org mode babel blocks.
  2020-05-04 15:26   ` Nicolas Goaziou
@ 2020-05-04 16:39     ` Roland Coeurjoly
  2020-05-04 21:49       ` Nicolas Goaziou
  0 siblings, 1 reply; 20+ messages in thread
From: Roland Coeurjoly @ 2020-05-04 16:39 UTC (permalink / raw)
  To: Roland Coeurjoly, emacs-orgmode

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

I am confused about the last point:
Use a let-binding instead of setq.

If I use:

(let* compile (string= (cdr (assq :compile params)) "yes"))

I get the following error:
ob-haskell.el:158:1: Error: Wrong type argument: listp, compile

If I leave with set:
(setq compile (string= (cdr (assq :compile params)) "yes"))
I get the following warnings:
ob-haskell.el:161:12: Warning: assignment to free variable ‘compile’
ob-haskell.el:161:12: Warning: reference to free variable ‘compile’

Upon searching the web, I find a relevant this relevant post
<https://emacs.stackexchange.com/questions/21245/dealing-with-warning-assignment-to-free-variable-when-certain-libraries-can-b>,
whose conclusion (if I understand it correctly) is that we could live with
those warning raised by setq.

Apart from this issue I am ready to submit a fixed patch.

What do you recommend?

On Mon, May 4, 2020 at 5:26 PM Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:

> Hello,
>
> Roland Coeurjoly <rolandcoeurjoly@gmail.com> writes:
>
> > From 091f470a278561a60fac1ee3ee658f6823bc2503 Mon Sep 17 00:00:00 2001
> > From: Roland Coeurjoly <rolandcoeurjoly@gmail.com>
> > Date: Sat, 25 Apr 2020 20:35:22 +0200
> > Subject: [PATCH] Add Haskell specific header argument compile, to compile
> >  instead of interpret the body of source block
>
> Thank you!
>
> Could you rewrite the commit message so that it is on par with our
> conventions?
>
> It could be something like:
>
>   ob-haskell: introduce :compile header argument
>
>   * lisp/ob-haskell (org-babel-haskell-compiler):
>   (org-babel-header-args:haskell): new variables.
>   (org-babel-haskell-execute):
>   (org-babel-haskell-interpret): new functions.
>   (org-babel-execute:haskell): use new functions.
>
> > -;; Org-Babel support for evaluating haskell source code.  This one will
> > -;; be sort of tricky because haskell programs must be compiled before
> > +;; Org-Babel support for evaluating Haskell source code.
> > +;; Haskell programs must be compiled before
>
> "Org Babel" would be even better, while you're changing this line.
>
> > +(defcustom org-babel-Haskell-compiler "ghc"
>
> No need to capitalize Haskell here.
>
> > +  "Command used to compile a Haskell source code file into an
> executable.
> > +May be either a command in the path, like ghc
>
> like "ghc"
>
> > +or an absolute path name, like /usr/local/bin/ghc
>
> like "/usr/local/bin/ghc".
>
> > +parameter may be used, like ghc -v"
>
> The command can include a parameter, such as "ghc -v".
>
> > +  :group 'org-babel
> > +  :version "27.0"
>
> It should be :package-version '(Org "9.4") instead.
>
> > +  :type 'string)
> > +
> > +(defconst org-babel-header-args:haskell '((compile . :any))
> > +  "Haskell-specific header arguments.")
> > +
> > +(defun org-babel-Haskell-execute (body params)
> > +  "This function should only be called by `org-babel-execute:haskell'"
> > +  (let* ((tmp-src-file (org-babel-temp-file
> > +                     "Haskell-src-"
> > +                        ".hs"))
>
> Indentation seems a bit off.
>
> > +         (tmp-bin-file
> > +          (org-babel-process-file-name
> > +           (org-babel-temp-file "Haskell-bin-" org-babel-exeext)))
> > +         (cmdline (cdr (assq :cmdline params)))
> > +         (cmdline (if cmdline (concat " " cmdline) ""))
> > +         (flags (cdr (assq :flags params)))
> > +         (flags (mapconcat 'identity
>
> Nitpick: #'identity
>
> > +                        (if (listp flags) flags (list flags)) " "))
> > +         (libs (org-babel-read
> > +             (or (cdr (assq :libs params))
> > +                 (org-entry-get nil "libs" t))
> > +             nil))
>
> Ditto, mind the indentation.
>
> > +         (libs (mapconcat #'identity
> > +                       (if (listp libs) libs (list libs))
> > +                       " ")))
> > +    (with-temp-file tmp-src-file (insert body))
> > +    (org-babel-eval
> > +     (format "%s -o %s %s %s %s"
> > +             org-babel-Haskell-compiler
> > +          tmp-bin-file
> > +          flags
> > +          (org-babel-process-file-name tmp-src-file)
> > +          libs) "")
>
> Please move the empty string below.
>
> > +    (let ((results
> > +        (org-babel-eval
> > +         (concat tmp-bin-file cmdline) "")))
> > +      (when results
> > +        (setq results (org-trim (org-remove-indentation results)))
> > +        (org-babel-reassemble-table
> > +         (org-babel-result-cond (cdr (assq :result-params params))
> > +        (org-babel-read results t)
> > +        (let ((tmp-file (org-babel-temp-file "Haskell-")))
> > +          (with-temp-file tmp-file (insert results))
> > +          (org-babel-import-elisp-from-file tmp-file)))
> > +         (org-babel-pick-name
> > +       (cdr (assq :colname-names params)) (cdr (assq :colnames params)))
> > +         (org-babel-pick-name
> > +       (cdr (assq :rowname-names params)) (cdr (assq :rownames
> params)))))
> > +      )))
>
> Please move the closing parens on the line above.
> > +
> > +(defun org-babel-interpret-Haskell (body params)
>
> Why capitalization in function names?
>
> >    (require 'inf-haskell)
> >    (add-hook 'inferior-haskell-hook
> >              (lambda ()
> > @@ -96,6 +154,14 @@ org-babel-execute:haskell
> >       (org-babel-pick-name (cdr (assq :rowname-names params))
> >                         (cdr (assq :rowname-names params))))))
> >
> > +
> > +(defun org-babel-execute:haskell (body params)
> > +  "Execute a block of Haskell code."
> > +  (setq compile (string= (cdr (assq :compile params)) "yes"))
>
> Use a let-binding instead of setq.
>
>
> Could you send an updated patch?
>
> Regards,
>
> --
> Nicolas Goaziou
>

[-- Attachment #2: Type: text/html, Size: 7627 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Fwd: Support compilation of Haskell in org mode babel blocks.
  2020-05-04 16:39     ` Roland Coeurjoly
@ 2020-05-04 21:49       ` Nicolas Goaziou
  2020-05-05 21:16         ` Roland Coeurjoly
  0 siblings, 1 reply; 20+ messages in thread
From: Nicolas Goaziou @ 2020-05-04 21:49 UTC (permalink / raw)
  To: Roland Coeurjoly; +Cc: emacs-orgmode

Roland Coeurjoly <rolandcoeurjoly@gmail.com> writes:

> I am confused about the last point:
> Use a let-binding instead of setq.
>
> If I use:
>
> (let* compile (string= (cdr (assq :compile params)) "yes"))

I meant: 

  (let ((compile (string= "yes" (cdr (assq :compile params)))))
   ...)


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Fwd: Support compilation of Haskell in org mode babel blocks.
  2020-05-04 15:42     ` Roland Coeurjoly
@ 2020-05-04 21:52       ` Nicolas Goaziou
  2020-05-05 21:23         ` Roland Coeurjoly
  0 siblings, 1 reply; 20+ messages in thread
From: Nicolas Goaziou @ 2020-05-04 21:52 UTC (permalink / raw)
  To: Roland Coeurjoly; +Cc: emacs-orgmode

Roland Coeurjoly <rolandcoeurjoly@gmail.com> writes:

> I have read the page about signing FSF papers, but I am unclear about how
> to proceed.
> Could you give some pointers?

Certainly. See

  https://orgmode.org/worg/org-contribute.html#copyright-issues

You basically need to fill a form and send it to assign@gnu.org.

Thank you for considering signing it.


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Fwd: Support compilation of Haskell in org mode babel blocks.
  2020-05-04 21:49       ` Nicolas Goaziou
@ 2020-05-05 21:16         ` Roland Coeurjoly
  2020-05-05 21:31           ` Nicolas Goaziou
  0 siblings, 1 reply; 20+ messages in thread
From: Roland Coeurjoly @ 2020-05-05 21:16 UTC (permalink / raw)
  To: Roland Coeurjoly, emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 433 bytes --]

Please see attached patch.
Regards.

On Mon, May 4, 2020 at 11:50 PM Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:

> Roland Coeurjoly <rolandcoeurjoly@gmail.com> writes:
>
> > I am confused about the last point:
> > Use a let-binding instead of setq.
> >
> > If I use:
> >
> > (let* compile (string= (cdr (assq :compile params)) "yes"))
>
> I meant:
>
>   (let ((compile (string= "yes" (cdr (assq :compile params)))))
>    ...)
>

[-- Attachment #1.2: Type: text/html, Size: 891 bytes --]

[-- Attachment #2: 0001-ob-haskell-introduce-compile-header-argument.patch --]
[-- Type: text/x-patch, Size: 4179 bytes --]

From 2c05ba85bffac4019432fa461c0e4f75cd24a0f6 Mon Sep 17 00:00:00 2001
From: Roland Coeurjoly <rolandcoeurjoly@gmail.com>
Date: Tue, 5 May 2020 23:09:58 +0200
Subject: [PATCH 1/1] ob-haskell: introduce :compile header argument

* lisp/ob-haskell (org-babel-haskell-compiler):
(org-babel-header-args:haskell): new variables.
(org-babel-haskell-execute):
(org-babel-haskell-interpret): new functions.
(org-babel-execute:haskell): use new functions.
---
 lisp/org/ob-haskell.el | 38 ++++++++++++++++++++------------------
 1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/lisp/org/ob-haskell.el b/lisp/org/ob-haskell.el
index d32a2f7bc0..55989adba1 100644
--- a/lisp/org/ob-haskell.el
+++ b/lisp/org/ob-haskell.el
@@ -23,7 +23,7 @@
 
 ;;; Commentary:
 
-;; Org-Babel support for evaluating Haskell source code.
+;; Org Babel support for evaluating Haskell source code.
 ;; Haskell programs must be compiled before
 ;; they can be run, but haskell code can also be run through an
 ;; interactive interpreter.
@@ -62,19 +62,19 @@ org-babel-haskell-eoe
 
 (defvar haskell-prompt-regexp)
 
-(defcustom org-babel-Haskell-compiler "ghc"
+(defcustom org-babel-haskell-compiler "ghc"
   "Command used to compile a Haskell source code file into an executable.
-May be either a command in the path, like ghc
-or an absolute path name, like /usr/local/bin/ghc
-parameter may be used, like ghc -v"
+May be either a command in the path, like \"ghc\"
+or an absolute path name, like \"/usr/local/bin/ghc\".
+The command can include a parameter, such as \"ghc -v\""
   :group 'org-babel
-  :version "27.0"
+  :package-version '(Org "9.4")
   :type 'string)
 
-(defconst org-babel-header-args:haskell '((compile . :any))
+(defconst org-babel-header-args:haskell '(compile . :any)
   "Haskell-specific header arguments.")
 
-(defun org-babel-Haskell-execute (body params)
+(defun org-babel-haskell-execute (body params)
   "This function should only be called by `org-babel-execute:haskell'"
   (let* ((tmp-src-file (org-babel-temp-file
 			"Haskell-src-"
@@ -85,8 +85,10 @@ org-babel-Haskell-execute
          (cmdline (cdr (assq :cmdline params)))
          (cmdline (if cmdline (concat " " cmdline) ""))
          (flags (cdr (assq :flags params)))
-         (flags (mapconcat 'identity
-		           (if (listp flags) flags (list flags)) " "))
+         (flags (mapconcat #'identity
+		           (if (listp flags)
+                               flags
+                             (list flags)) " "))
          (libs (org-babel-read
 	        (or (cdr (assq :libs params))
 	            (org-entry-get nil "libs" t))
@@ -97,11 +99,12 @@ org-babel-Haskell-execute
     (with-temp-file tmp-src-file (insert body))
     (org-babel-eval
      (format "%s -o %s %s %s %s"
-             org-babel-Haskell-compiler
+             org-babel-haskell-compiler
 	     tmp-bin-file
 	     flags
 	     (org-babel-process-file-name tmp-src-file)
-	     libs) "")
+	     libs)
+     "")
     (let ((results
 	   (org-babel-eval
 	    (concat tmp-bin-file cmdline) "")))
@@ -116,10 +119,9 @@ org-babel-Haskell-execute
          (org-babel-pick-name
 	  (cdr (assq :colname-names params)) (cdr (assq :colnames params)))
          (org-babel-pick-name
-	  (cdr (assq :rowname-names params)) (cdr (assq :rownames params)))))
-      )))
+	  (cdr (assq :rowname-names params)) (cdr (assq :rownames params))))))))
 
-(defun org-babel-interpret-Haskell (body params)
+(defun org-babel-interpret-haskell (body params)
   (require 'inf-haskell)
   (add-hook 'inferior-haskell-hook
             (lambda ()
@@ -157,10 +159,10 @@ org-babel-interpret-Haskell
 
 (defun org-babel-execute:haskell (body params)
   "Execute a block of Haskell code."
-  (setq compile (string= (cdr (assq :compile params)) "yes"))
+  (let ((compile (string= "yes" (cdr (assq :compile params)))))
   (if (not compile)
-      (org-babel-interpret-Haskell body params)
-    (org-babel-Haskell-execute body params)))
+      (org-babel-interpret-haskell body params)
+    (org-babel-haskell-execute body params))))
 
 (defun org-babel-haskell-initiate-session (&optional _session _params)
   "Initiate a haskell session.
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: Fwd: Support compilation of Haskell in org mode babel blocks.
  2020-05-04 21:52       ` Nicolas Goaziou
@ 2020-05-05 21:23         ` Roland Coeurjoly
  0 siblings, 0 replies; 20+ messages in thread
From: Roland Coeurjoly @ 2020-05-05 21:23 UTC (permalink / raw)
  To: Roland Coeurjoly, emacs-orgmode

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

I have sent the form.
Thank you.

On Mon, May 4, 2020 at 11:52 PM Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:

> Roland Coeurjoly <rolandcoeurjoly@gmail.com> writes:
>
> > I have read the page about signing FSF papers, but I am unclear about how
> > to proceed.
> > Could you give some pointers?
>
> Certainly. See
>
>   https://orgmode.org/worg/org-contribute.html#copyright-issues
>
> You basically need to fill a form and send it to assign@gnu.org.
>
> Thank you for considering signing it.
>

[-- Attachment #2: Type: text/html, Size: 1089 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Fwd: Support compilation of Haskell in org mode babel blocks.
  2020-05-05 21:16         ` Roland Coeurjoly
@ 2020-05-05 21:31           ` Nicolas Goaziou
  2020-05-05 21:42             ` Roland Coeurjoly
  2020-05-22  7:04             ` Roland Coeurjoly
  0 siblings, 2 replies; 20+ messages in thread
From: Nicolas Goaziou @ 2020-05-05 21:31 UTC (permalink / raw)
  To: Roland Coeurjoly; +Cc: emacs-orgmode

Hello,

Roland Coeurjoly <rolandcoeurjoly@gmail.com> writes:

> Please see attached patch.

Great!

It seems that this is a patch that needs to be applied on top of the
previous one. Could you merge them into a single patch and send it
again?

Please let me know when the FSF registers you.

Regards,

-- 
Nicolas Goaziou


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Fwd: Support compilation of Haskell in org mode babel blocks.
  2020-05-05 21:31           ` Nicolas Goaziou
@ 2020-05-05 21:42             ` Roland Coeurjoly
  2020-05-22  7:04             ` Roland Coeurjoly
  1 sibling, 0 replies; 20+ messages in thread
From: Roland Coeurjoly @ 2020-05-05 21:42 UTC (permalink / raw)
  To: Roland Coeurjoly, emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 488 bytes --]

Sorry about that. This attached patch should be good.

On Tue, May 5, 2020 at 11:31 PM Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:

> Hello,
>
> Roland Coeurjoly <rolandcoeurjoly@gmail.com> writes:
>
> > Please see attached patch.
>
> Great!
>
> It seems that this is a patch that needs to be applied on top of the
> previous one. Could you merge them into a single patch and send it
> again?
>
> Please let me know when the FSF registers you.
>
> Regards,
>
> --
> Nicolas Goaziou
>

[-- Attachment #1.2: Type: text/html, Size: 906 bytes --]

[-- Attachment #2: 0001-ob-haskell-introduce-compile-header-argument.patch --]
[-- Type: text/x-patch, Size: 4882 bytes --]

From 35d637fdad355787ce739d9b42997d3ba781a64f Mon Sep 17 00:00:00 2001
From: Roland Coeurjoly <rolandcoeurjoly@gmail.com>
Date: Sat, 25 Apr 2020 20:35:22 +0200
Subject: [PATCH 1/1] ob-haskell: introduce :compile header argument

* lisp/ob-haskell (org-babel-haskell-compiler):
(org-babel-header-args:haskell): new variables.
(org-babel-haskell-execute):
(org-babel-haskell-interpret): new functions.
(org-babel-execute:haskell): use new functions.
---
 lisp/org/ob-haskell.el | 78 ++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 73 insertions(+), 5 deletions(-)

diff --git a/lisp/org/ob-haskell.el b/lisp/org/ob-haskell.el
index e004a34..55989ad 100644
--- a/lisp/org/ob-haskell.el
+++ b/lisp/org/ob-haskell.el
@@ -23,12 +23,13 @@
 
 ;;; Commentary:
 
-;; Org-Babel support for evaluating haskell source code.  This one will
-;; be sort of tricky because haskell programs must be compiled before
+;; Org Babel support for evaluating Haskell source code.
+;; Haskell programs must be compiled before
 ;; they can be run, but haskell code can also be run through an
 ;; interactive interpreter.
 ;;
-;; For now lets only allow evaluation using the haskell interpreter.
+;; By default we evaluate using the Haskell interpreter.
+;; To use the compiler, specify :compile yes in the header.
 
 ;;; Requirements:
 
@@ -47,6 +48,7 @@
 (declare-function run-haskell "ext:inf-haskell" (&optional arg))
 (declare-function inferior-haskell-load-file
 		  "ext:inf-haskell" (&optional reload))
+(declare-function org-entry-get "org" (pom property &optional inherit literal-nil))
 
 (defvar org-babel-tangle-lang-exts)
 (add-to-list 'org-babel-tangle-lang-exts '("haskell" . "hs"))
@@ -60,8 +62,66 @@ org-babel-haskell-eoe
 
 (defvar haskell-prompt-regexp)
 
-(defun org-babel-execute:haskell (body params)
-  "Execute a block of Haskell code."
+(defcustom org-babel-haskell-compiler "ghc"
+  "Command used to compile a Haskell source code file into an executable.
+May be either a command in the path, like \"ghc\"
+or an absolute path name, like \"/usr/local/bin/ghc\".
+The command can include a parameter, such as \"ghc -v\""
+  :group 'org-babel
+  :package-version '(Org "9.4")
+  :type 'string)
+
+(defconst org-babel-header-args:haskell '(compile . :any)
+  "Haskell-specific header arguments.")
+
+(defun org-babel-haskell-execute (body params)
+  "This function should only be called by `org-babel-execute:haskell'"
+  (let* ((tmp-src-file (org-babel-temp-file
+			"Haskell-src-"
+                        ".hs"))
+         (tmp-bin-file
+          (org-babel-process-file-name
+           (org-babel-temp-file "Haskell-bin-" org-babel-exeext)))
+         (cmdline (cdr (assq :cmdline params)))
+         (cmdline (if cmdline (concat " " cmdline) ""))
+         (flags (cdr (assq :flags params)))
+         (flags (mapconcat #'identity
+		           (if (listp flags)
+                               flags
+                             (list flags)) " "))
+         (libs (org-babel-read
+	        (or (cdr (assq :libs params))
+	            (org-entry-get nil "libs" t))
+	        nil))
+         (libs (mapconcat #'identity
+		          (if (listp libs) libs (list libs))
+		          " ")))
+    (with-temp-file tmp-src-file (insert body))
+    (org-babel-eval
+     (format "%s -o %s %s %s %s"
+             org-babel-haskell-compiler
+	     tmp-bin-file
+	     flags
+	     (org-babel-process-file-name tmp-src-file)
+	     libs)
+     "")
+    (let ((results
+	   (org-babel-eval
+	    (concat tmp-bin-file cmdline) "")))
+      (when results
+        (setq results (org-trim (org-remove-indentation results)))
+        (org-babel-reassemble-table
+         (org-babel-result-cond (cdr (assq :result-params params))
+	   (org-babel-read results t)
+	   (let ((tmp-file (org-babel-temp-file "Haskell-")))
+	     (with-temp-file tmp-file (insert results))
+	     (org-babel-import-elisp-from-file tmp-file)))
+         (org-babel-pick-name
+	  (cdr (assq :colname-names params)) (cdr (assq :colnames params)))
+         (org-babel-pick-name
+	  (cdr (assq :rowname-names params)) (cdr (assq :rownames params))))))))
+
+(defun org-babel-interpret-haskell (body params)
   (require 'inf-haskell)
   (add-hook 'inferior-haskell-hook
             (lambda ()
@@ -96,6 +156,14 @@ org-babel-execute:haskell
      (org-babel-pick-name (cdr (assq :rowname-names params))
 			  (cdr (assq :rowname-names params))))))
 
+
+(defun org-babel-execute:haskell (body params)
+  "Execute a block of Haskell code."
+  (let ((compile (string= "yes" (cdr (assq :compile params)))))
+  (if (not compile)
+      (org-babel-interpret-haskell body params)
+    (org-babel-haskell-execute body params))))
+
 (defun org-babel-haskell-initiate-session (&optional _session _params)
   "Initiate a haskell session.
 If there is not a current inferior-process-buffer in SESSION
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: Fwd: Support compilation of Haskell in org mode babel blocks.
  2020-05-05 21:31           ` Nicolas Goaziou
  2020-05-05 21:42             ` Roland Coeurjoly
@ 2020-05-22  7:04             ` Roland Coeurjoly
  2020-05-22 15:30               ` Nicolas Goaziou
  1 sibling, 1 reply; 20+ messages in thread
From: Roland Coeurjoly @ 2020-05-22  7:04 UTC (permalink / raw)
  To: Roland Coeurjoly, emacs-orgmode

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

The assignment process with the FSF is complete.

Best regards,

Roland

On Tue, May 5, 2020 at 11:31 PM Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:

> Hello,
>
> Roland Coeurjoly <rolandcoeurjoly@gmail.com> writes:
>
> > Please see attached patch.
>
> Great!
>
> It seems that this is a patch that needs to be applied on top of the
> previous one. Could you merge them into a single patch and send it
> again?
>
> Please let me know when the FSF registers you.
>
> Regards,
>
> --
> Nicolas Goaziou
>

[-- Attachment #2: Type: text/html, Size: 983 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Fwd: Support compilation of Haskell in org mode babel blocks.
  2020-05-22  7:04             ` Roland Coeurjoly
@ 2020-05-22 15:30               ` Nicolas Goaziou
  2020-05-22 16:17                 ` Roland Coeurjoly
  0 siblings, 1 reply; 20+ messages in thread
From: Nicolas Goaziou @ 2020-05-22 15:30 UTC (permalink / raw)
  To: Roland Coeurjoly; +Cc: emacs-orgmode

Hello,

Roland Coeurjoly <rolandcoeurjoly@gmail.com> writes:

> The assignment process with the FSF is complete.

Great news!

Unfortunately, now I cannot your patch anymore. Would you mind rebasing
it on top of master, and add an entry in ORG-NEWS, probably in
"Miscellaneous" function.

Regards,

-- 
Nicolas Goaziou


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Fwd: Support compilation of Haskell in org mode babel blocks.
  2020-05-22 15:30               ` Nicolas Goaziou
@ 2020-05-22 16:17                 ` Roland Coeurjoly
  2020-05-23  5:12                   ` Kyle Meyer
  0 siblings, 1 reply; 20+ messages in thread
From: Roland Coeurjoly @ 2020-05-22 16:17 UTC (permalink / raw)
  To: Roland Coeurjoly, emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 524 bytes --]

I added version 9.4 to ORG-NEWS.
Please tell me if that's OK or I should instead put it in 9.3.

On Fri, May 22, 2020 at 5:30 PM Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:

> Hello,
>
> Roland Coeurjoly <rolandcoeurjoly@gmail.com> writes:
>
> > The assignment process with the FSF is complete.
>
> Great news!
>
> Unfortunately, now I cannot your patch anymore. Would you mind rebasing
> it on top of master, and add an entry in ORG-NEWS, probably in
> "Miscellaneous" function.
>
> Regards,
>
> --
> Nicolas Goaziou
>

[-- Attachment #1.2: Type: text/html, Size: 970 bytes --]

[-- Attachment #2: 0001-ob-haskell-introduce-compile-header-argument.patch --]
[-- Type: text/x-patch, Size: 5390 bytes --]

From daa91128ae38ffa47831c840b399144dd07c0b4a Mon Sep 17 00:00:00 2001
From: Roland Coeurjoly <rolandcoeurjoly@gmail.com>
Date: Sat, 25 Apr 2020 20:35:22 +0200
Subject: [PATCH 1/1] ob-haskell: introduce :compile header argument

* lisp/ob-haskell (org-babel-haskell-compiler):
(org-babel-header-args:haskell): new variables.
(org-babel-haskell-execute):
(org-babel-haskell-interpret): new functions.
(org-babel-execute:haskell): use new functions.
---
 etc/ORG-NEWS           |  9 +++++
 lisp/org/ob-haskell.el | 78 +++++++++++++++++++++++++++++++++++++++---
 2 files changed, 82 insertions(+), 5 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index ce08496b20..2ac4315aa4 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -10,6 +10,15 @@ See the end of the file for license conditions.
 
 Please send Org bug reports to mailto:emacs-orgmode@gnu.org.
 
+* Version 9.4
+
+** Incompatible changes
+** New features
+** New functions
+** Removed functions and variables
+** Miscellaneous
+*** ob-haskell: introduce :compile header argument
+
 * Version 9.3
 
 ** Incompatible changes
diff --git a/lisp/org/ob-haskell.el b/lisp/org/ob-haskell.el
index e004a3405e..55989adba1 100644
--- a/lisp/org/ob-haskell.el
+++ b/lisp/org/ob-haskell.el
@@ -23,12 +23,13 @@
 
 ;;; Commentary:
 
-;; Org-Babel support for evaluating haskell source code.  This one will
-;; be sort of tricky because haskell programs must be compiled before
+;; Org Babel support for evaluating Haskell source code.
+;; Haskell programs must be compiled before
 ;; they can be run, but haskell code can also be run through an
 ;; interactive interpreter.
 ;;
-;; For now lets only allow evaluation using the haskell interpreter.
+;; By default we evaluate using the Haskell interpreter.
+;; To use the compiler, specify :compile yes in the header.
 
 ;;; Requirements:
 
@@ -47,6 +48,7 @@
 (declare-function run-haskell "ext:inf-haskell" (&optional arg))
 (declare-function inferior-haskell-load-file
 		  "ext:inf-haskell" (&optional reload))
+(declare-function org-entry-get "org" (pom property &optional inherit literal-nil))
 
 (defvar org-babel-tangle-lang-exts)
 (add-to-list 'org-babel-tangle-lang-exts '("haskell" . "hs"))
@@ -60,8 +62,66 @@ org-babel-haskell-eoe
 
 (defvar haskell-prompt-regexp)
 
-(defun org-babel-execute:haskell (body params)
-  "Execute a block of Haskell code."
+(defcustom org-babel-haskell-compiler "ghc"
+  "Command used to compile a Haskell source code file into an executable.
+May be either a command in the path, like \"ghc\"
+or an absolute path name, like \"/usr/local/bin/ghc\".
+The command can include a parameter, such as \"ghc -v\""
+  :group 'org-babel
+  :package-version '(Org "9.4")
+  :type 'string)
+
+(defconst org-babel-header-args:haskell '(compile . :any)
+  "Haskell-specific header arguments.")
+
+(defun org-babel-haskell-execute (body params)
+  "This function should only be called by `org-babel-execute:haskell'"
+  (let* ((tmp-src-file (org-babel-temp-file
+			"Haskell-src-"
+                        ".hs"))
+         (tmp-bin-file
+          (org-babel-process-file-name
+           (org-babel-temp-file "Haskell-bin-" org-babel-exeext)))
+         (cmdline (cdr (assq :cmdline params)))
+         (cmdline (if cmdline (concat " " cmdline) ""))
+         (flags (cdr (assq :flags params)))
+         (flags (mapconcat #'identity
+		           (if (listp flags)
+                               flags
+                             (list flags)) " "))
+         (libs (org-babel-read
+	        (or (cdr (assq :libs params))
+	            (org-entry-get nil "libs" t))
+	        nil))
+         (libs (mapconcat #'identity
+		          (if (listp libs) libs (list libs))
+		          " ")))
+    (with-temp-file tmp-src-file (insert body))
+    (org-babel-eval
+     (format "%s -o %s %s %s %s"
+             org-babel-haskell-compiler
+	     tmp-bin-file
+	     flags
+	     (org-babel-process-file-name tmp-src-file)
+	     libs)
+     "")
+    (let ((results
+	   (org-babel-eval
+	    (concat tmp-bin-file cmdline) "")))
+      (when results
+        (setq results (org-trim (org-remove-indentation results)))
+        (org-babel-reassemble-table
+         (org-babel-result-cond (cdr (assq :result-params params))
+	   (org-babel-read results t)
+	   (let ((tmp-file (org-babel-temp-file "Haskell-")))
+	     (with-temp-file tmp-file (insert results))
+	     (org-babel-import-elisp-from-file tmp-file)))
+         (org-babel-pick-name
+	  (cdr (assq :colname-names params)) (cdr (assq :colnames params)))
+         (org-babel-pick-name
+	  (cdr (assq :rowname-names params)) (cdr (assq :rownames params))))))))
+
+(defun org-babel-interpret-haskell (body params)
   (require 'inf-haskell)
   (add-hook 'inferior-haskell-hook
             (lambda ()
@@ -96,6 +156,14 @@ org-babel-execute:haskell
      (org-babel-pick-name (cdr (assq :rowname-names params))
 			  (cdr (assq :rowname-names params))))))
 
+
+(defun org-babel-execute:haskell (body params)
+  "Execute a block of Haskell code."
+  (let ((compile (string= "yes" (cdr (assq :compile params)))))
+  (if (not compile)
+      (org-babel-interpret-haskell body params)
+    (org-babel-haskell-execute body params))))
+
 (defun org-babel-haskell-initiate-session (&optional _session _params)
   "Initiate a haskell session.
 If there is not a current inferior-process-buffer in SESSION
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: Fwd: Support compilation of Haskell in org mode babel blocks.
  2020-05-22 16:17                 ` Roland Coeurjoly
@ 2020-05-23  5:12                   ` Kyle Meyer
  2020-05-23 10:30                     ` Roland Coeurjoly
  0 siblings, 1 reply; 20+ messages in thread
From: Kyle Meyer @ 2020-05-23  5:12 UTC (permalink / raw)
  To: Roland Coeurjoly; +Cc: emacs-orgmode

Hi Roland,

Roland Coeurjoly writes:

> I added version 9.4 to ORG-NEWS.
> Please tell me if that's OK or I should instead put it in 9.3.

I don't think you managed to place your patch correctly on top of the
current master (5adfb533c at the time of writing) because ...

> --- a/etc/ORG-NEWS
> +++ b/etc/ORG-NEWS
> @@ -10,6 +10,15 @@ See the end of the file for license conditions.
>  
>  Please send Org bug reports to mailto:emacs-orgmode@gnu.org.
>  
> +* Version 9.4
> +
> +** Incompatible changes
> +** New features
> +** New functions
> +** Removed functions and variables
> +** Miscellaneous
> +*** ob-haskell: introduce :compile header argument

... ORG-NEWS in master already has a section for 9.4.

You can correct the situation by fetching and then rebasing onto master.


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Fwd: Support compilation of Haskell in org mode babel blocks.
  2020-05-23  5:12                   ` Kyle Meyer
@ 2020-05-23 10:30                     ` Roland Coeurjoly
  2020-05-23 14:02                       ` Bastien
  0 siblings, 1 reply; 20+ messages in thread
From: Roland Coeurjoly @ 2020-05-23 10:30 UTC (permalink / raw)
  To: Kyle Meyer; +Cc: emacs-orgmode

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

I have done a clean clone and I still don't see a 9.4 section in master.
Is it in another branch?

On Sat, May 23, 2020 at 7:12 AM Kyle Meyer <kyle@kyleam.com> wrote:

> Hi Roland,
>
> Roland Coeurjoly writes:
>
> > I added version 9.4 to ORG-NEWS.
> > Please tell me if that's OK or I should instead put it in 9.3.
>
> I don't think you managed to place your patch correctly on top of the
> current master (5adfb533c at the time of writing) because ...
>
> > --- a/etc/ORG-NEWS
> > +++ b/etc/ORG-NEWS
> > @@ -10,6 +10,15 @@ See the end of the file for license conditions.
> >
> >  Please send Org bug reports to mailto:emacs-orgmode@gnu.org.
> >
> > +* Version 9.4
> > +
> > +** Incompatible changes
> > +** New features
> > +** New functions
> > +** Removed functions and variables
> > +** Miscellaneous
> > +*** ob-haskell: introduce :compile header argument
>
> ... ORG-NEWS in master already has a section for 9.4.
>
> You can correct the situation by fetching and then rebasing onto master.
>

[-- Attachment #2: Type: text/html, Size: 1513 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Fwd: Support compilation of Haskell in org mode babel blocks.
  2020-05-23 10:30                     ` Roland Coeurjoly
@ 2020-05-23 14:02                       ` Bastien
  2020-05-23 14:51                         ` Roland Coeurjoly
  0 siblings, 1 reply; 20+ messages in thread
From: Bastien @ 2020-05-23 14:02 UTC (permalink / raw)
  To: Roland Coeurjoly; +Cc: emacs-orgmode

Hi Roland,

Roland Coeurjoly <rolandcoeurjoly@gmail.com> writes:

> I have done a clean clone and I still don't see a 9.4 section in
> master.
> Is it in another branch?

It is here in the master branch:

https://code.orgmode.org/bzg/org-mode/src/master/etc/ORG-NEWS#L13

-- 
 Bastien


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Fwd: Support compilation of Haskell in org mode babel blocks.
  2020-05-23 14:02                       ` Bastien
@ 2020-05-23 14:51                         ` Roland Coeurjoly
  2020-05-23 15:21                           ` Bastien
  2020-05-25  7:19                           ` Nicolas Goaziou
  0 siblings, 2 replies; 20+ messages in thread
From: Roland Coeurjoly @ 2020-05-23 14:51 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 493 bytes --]

Sorry, I was working on the emacs git repo, which seems to be a bit behind
the org mode one.
Please find patch attached.

On Sat, May 23, 2020 at 4:02 PM Bastien <bzg@gnu.org> wrote:

> Hi Roland,
>
> Roland Coeurjoly <rolandcoeurjoly@gmail.com> writes:
>
> > I have done a clean clone and I still don't see a 9.4 section in
> > master.
> > Is it in another branch?
>
> It is here in the master branch:
>
> https://code.orgmode.org/bzg/org-mode/src/master/etc/ORG-NEWS#L13
>
> --
>  Bastien
>

[-- Attachment #1.2: Type: text/html, Size: 1031 bytes --]

[-- Attachment #2: 0001-ob-haskell-introduce-compile-header-argument.patch --]
[-- Type: text/x-patch, Size: 5550 bytes --]

From 4d8660eea35ea13809914271562f0ff73507f967 Mon Sep 17 00:00:00 2001
From: Roland Coeurjoly <rolandcoeurjoly@gmail.com>
Date: Sat, 23 May 2020 16:46:26 +0200
Subject: [PATCH 1/1] ob-haskell: introduce :compile header argument

  * lisp/ob-haskell (org-babel-haskell-compiler):
  (org-babel-header-args:haskell): new variables.
  (org-babel-haskell-execute):
  (org-babel-haskell-interpret): new functions.
  (org-babel-execute:haskell): use new functions.
---
 etc/ORG-NEWS       |  6 ++++
 lisp/ob-haskell.el | 80 +++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 81 insertions(+), 5 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index f8bddb613..21c5e3d71 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -453,6 +453,12 @@ equations producing inconsistent output. New option
 ~org-html-equation-reference-format~ sets the command used in HTML
 export.
 
+*** ob-haskell: add support for compilation with :compile header argument
+
+By default, Haskell blocks are interpreted. By adding ~:compile yes~
+to a Haskell source block, it will be compiled, executed and
+the results will be displayed.
+
 * Version 9.3
 
 ** Incompatible changes
diff --git a/lisp/ob-haskell.el b/lisp/ob-haskell.el
index bea162528..466344ac0 100644
--- a/lisp/ob-haskell.el
+++ b/lisp/ob-haskell.el
@@ -23,12 +23,13 @@
 
 ;;; Commentary:
 
-;; Org-Babel support for evaluating haskell source code.  This one will
-;; be sort of tricky because haskell programs must be compiled before
+;; Org Babel support for evaluating Haskell source code.
+;; Haskell programs must be compiled before
 ;; they can be run, but haskell code can also be run through an
 ;; interactive interpreter.
 ;;
-;; For now lets only allow evaluation using the haskell interpreter.
+;; By default we evaluate using the Haskell interpreter.
+;; To use the compiler, specify :compile yes in the header.
 
 ;;; Requirements:
 
@@ -45,6 +46,7 @@
 (declare-function run-haskell "ext:inf-haskell" (&optional arg))
 (declare-function inferior-haskell-load-file
 		  "ext:inf-haskell" (&optional reload))
+(declare-function org-entry-get "org" (pom property &optional inherit literal-nil))
 
 (defvar org-babel-tangle-lang-exts)
 (add-to-list 'org-babel-tangle-lang-exts '("haskell" . "hs"))
@@ -58,8 +60,66 @@
 
 (defvar haskell-prompt-regexp)
 
-(defun org-babel-execute:haskell (body params)
-  "Execute a block of Haskell code."
+(defcustom org-babel-haskell-compiler "ghc"
+  "Command used to compile a Haskell source code file into an executable.
+May be either a command in the path, like \"ghc\"
+or an absolute path name, like \"/usr/local/bin/ghc\".
+The command can include a parameter, such as \"ghc -v\""
+  :group 'org-babel
+  :package-version '(Org "9.4")
+  :type 'string)
+
+(defconst org-babel-header-args:haskell '(compile . :any)
+  "Haskell-specific header arguments.")
+
+(defun org-babel-haskell-execute (body params)
+  "This function should only be called by `org-babel-execute:haskell'"
+  (let* ((tmp-src-file (org-babel-temp-file
+			"Haskell-src-"
+                        ".hs"))
+         (tmp-bin-file
+          (org-babel-process-file-name
+           (org-babel-temp-file "Haskell-bin-" org-babel-exeext)))
+         (cmdline (cdr (assq :cmdline params)))
+         (cmdline (if cmdline (concat " " cmdline) ""))
+         (flags (cdr (assq :flags params)))
+         (flags (mapconcat #'identity
+		           (if (listp flags)
+                               flags
+                             (list flags)) " "))
+         (libs (org-babel-read
+	        (or (cdr (assq :libs params))
+	            (org-entry-get nil "libs" t))
+	        nil))
+         (libs (mapconcat #'identity
+		          (if (listp libs) libs (list libs))
+		          " ")))
+    (with-temp-file tmp-src-file (insert body))
+    (org-babel-eval
+     (format "%s -o %s %s %s %s"
+             org-babel-haskell-compiler
+	     tmp-bin-file
+	     flags
+	     (org-babel-process-file-name tmp-src-file)
+	     libs)
+     "")
+    (let ((results
+	   (org-babel-eval
+	    (concat tmp-bin-file cmdline) "")))
+      (when results
+        (setq results (org-trim (org-remove-indentation results)))
+        (org-babel-reassemble-table
+         (org-babel-result-cond (cdr (assq :result-params params))
+	   (org-babel-read results t)
+	   (let ((tmp-file (org-babel-temp-file "Haskell-")))
+	     (with-temp-file tmp-file (insert results))
+	     (org-babel-import-elisp-from-file tmp-file)))
+         (org-babel-pick-name
+	  (cdr (assq :colname-names params)) (cdr (assq :colnames params)))
+         (org-babel-pick-name
+	  (cdr (assq :rowname-names params)) (cdr (assq :rownames params))))))))
+
+(defun org-babel-interpret-haskell (body params)
   (require 'inf-haskell)
   (add-hook 'inferior-haskell-hook
             (lambda ()
@@ -94,6 +154,14 @@
      (org-babel-pick-name (cdr (assq :rowname-names params))
 			  (cdr (assq :rowname-names params))))))
 
+
+(defun org-babel-execute:haskell (body params)
+  "Execute a block of Haskell code."
+  (let ((compile (string= "yes" (cdr (assq :compile params)))))
+  (if (not compile)
+      (org-babel-interpret-haskell body params)
+    (org-babel-haskell-execute body params))))
+
 (defun org-babel-haskell-initiate-session (&optional _session _params)
   "Initiate a haskell session.
 If there is not a current inferior-process-buffer in SESSION
@@ -213,4 +281,6 @@ constructs (header arguments, no-web syntax etc...) are ignored."
 
 (provide 'ob-haskell)
 
+
+
 ;;; ob-haskell.el ends here
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: Fwd: Support compilation of Haskell in org mode babel blocks.
  2020-05-23 14:51                         ` Roland Coeurjoly
@ 2020-05-23 15:21                           ` Bastien
  2020-05-25  7:19                           ` Nicolas Goaziou
  1 sibling, 0 replies; 20+ messages in thread
From: Bastien @ 2020-05-23 15:21 UTC (permalink / raw)
  To: Roland Coeurjoly; +Cc: emacs-orgmode

Hi Roland,

Roland Coeurjoly <rolandcoeurjoly@gmail.com> writes:

> Please find patch attached.

Thanks -- I'll let Nicolas apply it, since he has been following this,
but just some nitpicking for later contributions below:

> From 4d8660eea35ea13809914271562f0ff73507f967 Mon Sep 17 00:00:00 2001
> From: Roland Coeurjoly <rolandcoeurjoly@gmail.com>
> Date: Sat, 23 May 2020 16:46:26 +0200
> Subject: [PATCH 1/1] ob-haskell: introduce :compile header argument
>
>   * lisp/ob-haskell (org-babel-haskell-compiler):
>   (org-babel-header-args:haskell): new variables.
>   (org-babel-haskell-execute):
>   (org-babel-haskell-interpret): new functions.
>   (org-babel-execute:haskell): use new functions.

"new variables." should be capitalized as "New variables."

>  (provide 'ob-haskell)
>  
> +
> +
>  ;;; ob-haskell.el ends here

You can get rid of these empty lines at the end.

Thanks,

-- 
 Bastien


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: Fwd: Support compilation of Haskell in org mode babel blocks.
  2020-05-23 14:51                         ` Roland Coeurjoly
  2020-05-23 15:21                           ` Bastien
@ 2020-05-25  7:19                           ` Nicolas Goaziou
  1 sibling, 0 replies; 20+ messages in thread
From: Nicolas Goaziou @ 2020-05-25  7:19 UTC (permalink / raw)
  To: Roland Coeurjoly; +Cc: Bastien, emacs-orgmode

Hello,

Roland Coeurjoly <rolandcoeurjoly@gmail.com> writes:

> Sorry, I was working on the emacs git repo, which seems to be a bit behind
> the org mode one.
> Please find patch attached.

I removed some spurious blank lines and applied your patch.

Thank you.

Regards,

-- 
Nicolas Goaziou


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2020-05-25  7:20 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CAMdauZqv91_bW2aZj=AT32vBdyPia92vjeVFMmsFazsEhJCTHg@mail.gmail.com>
2020-04-28 14:56 ` Fwd: Support compilation of Haskell in org mode babel blocks Roland Coeurjoly
2020-05-04 15:26   ` Nicolas Goaziou
2020-05-04 16:39     ` Roland Coeurjoly
2020-05-04 21:49       ` Nicolas Goaziou
2020-05-05 21:16         ` Roland Coeurjoly
2020-05-05 21:31           ` Nicolas Goaziou
2020-05-05 21:42             ` Roland Coeurjoly
2020-05-22  7:04             ` Roland Coeurjoly
2020-05-22 15:30               ` Nicolas Goaziou
2020-05-22 16:17                 ` Roland Coeurjoly
2020-05-23  5:12                   ` Kyle Meyer
2020-05-23 10:30                     ` Roland Coeurjoly
2020-05-23 14:02                       ` Bastien
2020-05-23 14:51                         ` Roland Coeurjoly
2020-05-23 15:21                           ` Bastien
2020-05-25  7:19                           ` Nicolas Goaziou
2020-05-04 15:29   ` Nicolas Goaziou
2020-05-04 15:42     ` Roland Coeurjoly
2020-05-04 21:52       ` Nicolas Goaziou
2020-05-05 21:23         ` Roland Coeurjoly

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).