emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Haskell org-mode problems redux
@ 2019-05-30 17:55 Lawrence Bottorff
  2019-05-30 21:25 ` Bruno Barbier
  0 siblings, 1 reply; 3+ messages in thread
From: Lawrence Bottorff @ 2019-05-30 17:55 UTC (permalink / raw)
  To: emacs-orgmode Mailinglist

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

I've been trying to get Haskell to work in babel code blocks for a long
time. A year or so ago I tried and eventually gave up. I tried again
recently . . . same old problems, i.e., the code block is evaluated
exclusively by the ghci REPL, which doesn't understand or play well with an
org babel code block.

Before, the recipe was to add `:set +m` to either the top of the block or
run it in the REPL to allow "multiple lines" declarations, e.g., functions.
Then there was the `let` in front of a function declaration, which is also
a REPL workaround. Now it seems you need the :{ ... :} trick to get all the
code block lines to be seen as together, i.e.,

#+begin_src haskell :results raw
:{
  doubleSmallNumber x =
    if x > 10
    then x
    else x * 2
:}
#+end_src

otherwise the block is treated as though it is being fed into the REPL one
at a time with no idea these lines are together making a function
declaration. I'm on latest org, have installed Haskell stack 8.6.3 on
Ubuntu (Haskell stack 8.6.5 on Windows). The maddening thing is the
intermittent behavior, i.e., sometimes it likes what you're doing:

 #+begin_src haskell :results raw
tripleMe x = x + x + x
#+end_src

and

#+begin_src haskell :results raw
[x | x <- [0..100], x `mod` 2 == 0 && x `mod` 7 == 0]
#+end_src

#+RESULTS:
Prelude> [0,14,28,42,56,70,84,98]
[0,14,28,42,56,70,84,98]

work fine -- but often enough when trying to declare a function with type
declaration first I get cryptic errors -- which are then solved with the :{
... :} REPL kludge. One other oddness is starting a ghci session with babel
creates a different sort of REPL than just starting one with haskell-mode .
. . and the two REPLs seem to clash and not like each other around.
Declaring :session *haskell* doesn't seem to matter. . . .

I was in touch with Rob Moss who claims to have it all working with GHC 4.4
from Debian and spacemacs, but when I tried all that I wasn't able to
reproduce his results, rather, the same old problems.

Soooo, any ideas? It seems like ob-haskell -- which is now built in, not
separate? -- needs some attention. Or somebody who has the proverbial
silver bullet comes forth to save the day.

LB

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

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

* Re: Haskell org-mode problems redux
  2019-05-30 17:55 Haskell org-mode problems redux Lawrence Bottorff
@ 2019-05-30 21:25 ` Bruno Barbier
  2019-05-31  3:40   ` Lawrence Bottorff
  0 siblings, 1 reply; 3+ messages in thread
From: Bruno Barbier @ 2019-05-30 21:25 UTC (permalink / raw)
  To: Lawrence Bottorff, emacs-orgmode Mailinglist


Hi Lawrence,


Lawrence Bottorff <borgauf@gmail.com> writes:

> I've been trying to get Haskell to work in babel code blocks for a long
> time. A year or so ago I tried and eventually gave up. I tried again
> recently . . . same old problems, i.e., the code block is evaluated
> exclusively by the ghci REPL, which doesn't understand or play well with an
> org babel code block.
>
...
> Soooo, any ideas?

I'm using the header arguments:


    :prologue ":{\n" :epilogue ":}\n" 

     

to request org to insert those multiline tags :{ :} 
(so, I'm not using ":set +m").

I'm defining these header args as headline properties (so that I don't
have to enter them again and again).  Something like that:

  #+begin_example
    ,** A title
       :PROPERTIES:
       :header-args:haskell: :prologue ":{\n" :epilogue ":}\n"
       :END:
  #+end_example

I'm telling ghci to not insert a prompt, when waiting for the end of a
multiline.

#+begin_src haskell
:set prompt-cont ""
#+end_src


Configured like this, it seems to be working quite well for me (great
job org and GHC teams!).


#+begin_src haskell
  doubleSmallNumber x =
      if x > 10
          then x
          else x * 2
#+end_src

No error.

#+begin_src haskell
let
    showMe :: Int -> [String]
    showMe x = [show x, show $ doubleSmallNumber x]
in 
  [ ["x", "doubleSmallNumber x"]
  , showMe 3
  , showMe 13
  ]
#+end_src

#+RESULTS:
    |  x | doubleSmallNumber x |
    |  3 |                   6 |
    | 13 |                  13 |



My config:

    | ghci  | 8.6.3 |
    | emacs |  26.1 |
    | org   | 9.2.3 |
    | OS    | linux |


If it doesn't work for you on GNU/Linux, post the example and I will try
it on my computer (sorry, I won't be able to help you with Microsoft
Windows though).



Bruno


> LB

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

* Re: Haskell org-mode problems redux
  2019-05-30 21:25 ` Bruno Barbier
@ 2019-05-31  3:40   ` Lawrence Bottorff
  0 siblings, 0 replies; 3+ messages in thread
From: Lawrence Bottorff @ 2019-05-31  3:40 UTC (permalink / raw)
  To: Bruno Barbier; +Cc: emacs-orgmode Mailinglist

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

Gosh, it worked. So I wasn't crazy or remiss, rather, I just didn't know
how deep the rabbit hole was. Thanks! One odd thing still. I tried to run

#+begin_src haskell
:set prompt-cont ""
#+end_src

and like other times before trying to run Haskell blocks it complained
saying

executing Haskell code block...
org-babel-script-escape: ‘org-babel-script-escape’ expects a string

so I add :results output to the #+begin line and it works. Would anyone
know what that is about?


On Thu, May 30, 2019 at 3:25 PM Bruno Barbier <brubar.cs@gmail.com> wrote:

>
> Hi Lawrence,
>
>
> Lawrence Bottorff <borgauf@gmail.com> writes:
>
> > I've been trying to get Haskell to work in babel code blocks for a long
> > time. A year or so ago I tried and eventually gave up. I tried again
> > recently . . . same old problems, i.e., the code block is evaluated
> > exclusively by the ghci REPL, which doesn't understand or play well with
> an
> > org babel code block.
> >
> ...
> > Soooo, any ideas?
>
> I'm using the header arguments:
>
>
>     :prologue ":{\n" :epilogue ":}\n"
>
>
>
> to request org to insert those multiline tags :{ :}
> (so, I'm not using ":set +m").
>
> I'm defining these header args as headline properties (so that I don't
> have to enter them again and again).  Something like that:
>
>   #+begin_example
>     ,** A title
>        :PROPERTIES:
>        :header-args:haskell: :prologue ":{\n" :epilogue ":}\n"
>        :END:
>   #+end_example
>
> I'm telling ghci to not insert a prompt, when waiting for the end of a
> multiline.
>
> #+begin_src haskell
> :set prompt-cont ""
> #+end_src
>
>
> Configured like this, it seems to be working quite well for me (great
> job org and GHC teams!).
>
>
> #+begin_src haskell
>   doubleSmallNumber x =
>       if x > 10
>           then x
>           else x * 2
> #+end_src
>
> No error.
>
> #+begin_src haskell
> let
>     showMe :: Int -> [String]
>     showMe x = [show x, show $ doubleSmallNumber x]
> in
>   [ ["x", "doubleSmallNumber x"]
>   , showMe 3
>   , showMe 13
>   ]
> #+end_src
>
> #+RESULTS:
>     |  x | doubleSmallNumber x |
>     |  3 |                   6 |
>     | 13 |                  13 |
>
>
>
> My config:
>
>     | ghci  | 8.6.3 |
>     | emacs |  26.1 |
>     | org   | 9.2.3 |
>     | OS    | linux |
>
>
> If it doesn't work for you on GNU/Linux, post the example and I will try
> it on my computer (sorry, I won't be able to help you with Microsoft
> Windows though).
>
>
>
> Bruno
>
>
> > LB
>

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

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

end of thread, other threads:[~2019-05-31  3:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-30 17:55 Haskell org-mode problems redux Lawrence Bottorff
2019-05-30 21:25 ` Bruno Barbier
2019-05-31  3:40   ` Lawrence Bottorff

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