Re: Fwd: Support compilation of Haskell in org mode babel blocks.

2020-05-25 Thread Nicolas Goaziou
Hello,

Roland Coeurjoly  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



Re: Fwd: Support compilation of Haskell in org mode babel blocks.

2020-05-23 Thread Bastien
Hi Roland,

Roland Coeurjoly  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 
> 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



Re: Fwd: Support compilation of Haskell in org mode babel blocks.

2020-05-23 Thread Roland Coeurjoly
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  wrote:

> Hi Roland,
>
> Roland Coeurjoly  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
>
From 4d8660eea35ea13809914271562f0ff73507f967 Mon Sep 17 00:00:00 2001
From: Roland Coeurjoly 
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" ( arg))
 (declare-function inferior-haskell-load-file
 		  "ext:inf-haskell" ( reload))
+(declare-function org-entry-get "org" (pom property  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)))
+ 

Re: Fwd: Support compilation of Haskell in org mode babel blocks.

2020-05-23 Thread Bastien
Hi Roland,

Roland Coeurjoly  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



Re: Fwd: Support compilation of Haskell in org mode babel blocks.

2020-05-23 Thread Roland Coeurjoly
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  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.
>


Re: Fwd: Support compilation of Haskell in org mode babel blocks.

2020-05-22 Thread Kyle Meyer
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.



Re: Fwd: Support compilation of Haskell in org mode babel blocks.

2020-05-22 Thread Roland Coeurjoly
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 
wrote:

> Hello,
>
> Roland Coeurjoly  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
>
From daa91128ae38ffa47831c840b399144dd07c0b4a Mon Sep 17 00:00:00 2001
From: Roland Coeurjoly 
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" ( arg))
 (declare-function inferior-haskell-load-file
 		  "ext:inf-haskell" ( reload))
+(declare-function org-entry-get "org" (pom property  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 

Re: Fwd: Support compilation of Haskell in org mode babel blocks.

2020-05-22 Thread Nicolas Goaziou
Hello,

Roland Coeurjoly  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



Re: Fwd: Support compilation of Haskell in org mode babel blocks.

2020-05-22 Thread Roland Coeurjoly
The assignment process with the FSF is complete.

Best regards,

Roland

On Tue, May 5, 2020 at 11:31 PM Nicolas Goaziou 
wrote:

> Hello,
>
> Roland Coeurjoly  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
>


Re: Fwd: Support compilation of Haskell in org mode babel blocks.

2020-05-05 Thread Roland Coeurjoly
Sorry about that. This attached patch should be good.

On Tue, May 5, 2020 at 11:31 PM Nicolas Goaziou 
wrote:

> Hello,
>
> Roland Coeurjoly  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
>
From 35d637fdad355787ce739d9b42997d3ba781a64f Mon Sep 17 00:00:00 2001
From: Roland Coeurjoly 
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" ( arg))
 (declare-function inferior-haskell-load-file
 		  "ext:inf-haskell" ( reload))
+(declare-function org-entry-get "org" (pom property  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)
+  

Re: Fwd: Support compilation of Haskell in org mode babel blocks.

2020-05-05 Thread Nicolas Goaziou
Hello,

Roland Coeurjoly  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



Re: Fwd: Support compilation of Haskell in org mode babel blocks.

2020-05-05 Thread Roland Coeurjoly
I have sent the form.
Thank you.

On Mon, May 4, 2020 at 11:52 PM Nicolas Goaziou 
wrote:

> Roland Coeurjoly  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 ass...@gnu.org.
>
> Thank you for considering signing it.
>


Re: Fwd: Support compilation of Haskell in org mode babel blocks.

2020-05-05 Thread Roland Coeurjoly
Please see attached patch.
Regards.

On Mon, May 4, 2020 at 11:50 PM Nicolas Goaziou 
wrote:

> Roland Coeurjoly  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)
>...)
>
From 2c05ba85bffac4019432fa461c0e4f75cd24a0f6 Mon Sep 17 00:00:00 2001
From: Roland Coeurjoly 
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 ( _session _params)
   "Initiate a haskell session.
-- 
2.20.1



Re: Fwd: Support compilation of Haskell in org mode babel blocks.

2020-05-04 Thread Nicolas Goaziou
Roland Coeurjoly  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)
   ...)



Re: Fwd: Support compilation of Haskell in org mode babel blocks.

2020-05-04 Thread Nicolas Goaziou
Roland Coeurjoly  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 ass...@gnu.org.

Thank you for considering signing it.



Re: Fwd: Support compilation of Haskell in org mode babel blocks.

2020-05-04 Thread Roland Coeurjoly
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
,
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 
wrote:

> Hello,
>
> Roland Coeurjoly  writes:
>
> > From 091f470a278561a60fac1ee3ee658f6823bc2503 Mon Sep 17 00:00:00 2001
> > From: Roland Coeurjoly 
> > 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 

Re: Fwd: Support compilation of Haskell in org mode babel blocks.

2020-05-04 Thread Roland Coeurjoly
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 
wrote:

> Roland Coeurjoly  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.
>


Re: Fwd: Support compilation of Haskell in org mode babel blocks.

2020-05-04 Thread Nicolas Goaziou
Roland Coeurjoly  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.



Re: Fwd: Support compilation of Haskell in org mode babel blocks.

2020-05-04 Thread Nicolas Goaziou
Hello,

Roland Coeurjoly  writes:

> From 091f470a278561a60fac1ee3ee658f6823bc2503 Mon Sep 17 00:00:00 2001
> From: Roland Coeurjoly 
> 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



Fwd: Support compilation of Haskell in org mode babel blocks.

2020-04-28 Thread Roland Coeurjoly
-- Forwarded message -
From: Roland Coeurjoly 
Date: Sat, Apr 25, 2020 at 9:04 PM
Subject: Support compilation of Haskell in org mode babel blocks.
To: 


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

.

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.
From 091f470a278561a60fac1ee3ee658f6823bc2503 Mon Sep 17 00:00:00 2001
From: Roland Coeurjoly 
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" ( arg))
 (declare-function inferior-haskell-load-file
 		  "ext:inf-haskell" ( reload))
+(declare-function org-entry-get "org" (pom property  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