<div dir="ltr">Hi,<div class="gmail-moz-forward-container"><p>
      If you are already running atop the Jupyter technology
      stack, IHaskel [1] may be very straight forward to be
      incorporated from technical aspect (while licensing aspect is out
      of my expertise).<br>
      <br>
      But still I would like take this opportunity to have more/further
      evaluation from you, about [2] , with by far my implementation
      [3] and application [4].<br>
      <br>
      Once a frontend plugin can be injected into a GHCi session, and hooked up to some interactive UI, a new door
      is opened to allow much easier setup & use of GHC API
      interactively, like demonstrated in Hadui [4]. <br>
    </p>
    <p>Currently there are too many different ways to setup a GHC API
      session, HIE has tried hard to unify them, but itself is yet under
      transition. I see the frontend interface being a proper abstraction
      even extended to WebUI/GUI applications, making interactions perfectly
      decoupled from how the underlying artifacts are organized, thus
      worth further consideration.<br>
      <br>
      While IHaskell is more powerful and better established as with
      Jupyter notebook, I chose the frontend route because IHaskell
      didn't come to today's maturity when I needed something like
      Hadui, and ZeroMQ seems bloating to my cases, even for now.<br>
      <br>
      Cheers,<br>
      Compl<br>
    </p>
    <p>[1] <a class="gmail-moz-txt-link-freetext" href="https://github.com/gibiansky/IHaskell">https://github.com/gibiansky/IHaskell</a></p>
    <p>[2] <a class="gmail-moz-txt-link-freetext" href="https://gitlab.haskell.org/ghc/ghc/issues/17348">https://gitlab.haskell.org/ghc/ghc/issues/17348</a></p>
    <p>[3] <a href="https://gitlab.haskell.org/complyue/ghc/tree/ghc-8.6-ife">https://gitlab.haskell.org/complyue/ghc/tree/ghc-8.6-ife</a></p>
    <p>[4] <a class="gmail-moz-txt-link-freetext" href="https://github.com/complyue/hadui">https://github.com/complyue/hadui</a> </p>
    <p><br>
    </p>
    <div class="gmail-moz-cite-prefix">On 2020/5/1 上午5:13, Ben Gamari wrote:<br>
    </div>
    <blockquote type="cite">
      <pre class="gmail-moz-quote-pre">Simon Peyton Jones via ghc-devs <a class="gmail-moz-txt-link-rfc2396E" href="mailto:ghc-devs@haskell.org"><ghc-devs@haskell.org></a> writes:

</pre>
      <blockquote type="cite">
        <pre class="gmail-moz-quote-pre">Friends

Short summary: can someone familiar with using the GHC API offer
advice on getting the Wolfram Language connected to Haskell?

</pre>
      </blockquote>
      <pre class="gmail-moz-quote-pre">Hi Todd, et al.,

This sounds like a great project. I have fond memories of Mathematica
from my studies.

...

</pre>
      <blockquote type="cite">
        <pre class="gmail-moz-quote-pre">We have the following basic line of code for evaluating a string of Haskell code:

    r <- liftIO $ runInterpreter $ do { setImports ["Prelude"]; eval strToEvaluate}

The problem is that this is a one-shot evaluation, and we want a
long-lived interactive Haskell session, to which a series of inputs
can be directed. We have been told that we have to use GHCi for that,
but we don't know how to do it.

</pre>
      </blockquote>
      <pre class="gmail-moz-quote-pre">It appears that you are using the `hint` library [1] for evaluation.
I'll admit that I've not used hint; it looks quite sensible but I do not
know what limitations you might encounter. It looks like its approach to
error handling may leave something to be desired. Nevertheless, we can
work with it for now; if we run into its limitations then the
alternative is to use the GHC API directly, as suggested by Simon.

</pre>
      <blockquote type="cite">
        <pre class="gmail-moz-quote-pre">The basic flow of our functionality is as follows:

1) User calls StartExternalSession["LanguageName"] to launch an
interpreter for the language. This process remains running and can be
used for multiple calls.

2) User calls ExternalEvaluate[session, "some code"] to execute the
given code in the external language and return a result converted into
native Wolfram Language types (strings, numbers, lists, associations,
etc.)

</pre>
      </blockquote>
      <pre class="gmail-moz-quote-pre">Sure.

...

</pre>
      <blockquote type="cite">
        <pre class="gmail-moz-quote-pre">We have attached a simple file of Haskell code that one of our
engineers has successfully used to get a basic evaluation of Haskell
code from the Wolfram Language, but it uses the single-shot evaluation
code that was given above, and so is not suitable. We would appreciate
any help that you can give us, or developers or resources you can
point us at, to assist in integrating Haskell into our
ExternalEvaluate system.

</pre>
      </blockquote>
      <pre class="gmail-moz-quote-pre">It looks like you will want to push the `runInterpreter` out of the
`forever`. Afterall, you want the interpreter session to persist over
multiple requests. Doing this isn't difficult but does require some
monad transformer shuffling, which may be unfamiliar to someone coming
from another language. I've put up a cleaned up version of your program
here [1]; hopefully this is enough to get you started. Do note that this
requires a patched version of zeromq4-haskell due to a minor bug [2]
which I have fixed [3].

Do note that there is a related effort, iHaskell [4], which provides a
Haskell kernel for Jupyter Notebook. This might be a place to draw
inspiration from.

Let us know how things go and don't hesitate to be in touch if you have
questions regarding the GHC API.

Cheers,

- Ben


[1] <a class="gmail-moz-txt-link-freetext" href="https://github.com/bgamari/zeromq-hint">https://github.com/bgamari/zeromq-hint</a>
[2] <a class="gmail-moz-txt-link-freetext" href="https://gitlab.com/twittner/zeromq-haskell/-/issues/66">https://gitlab.com/twittner/zeromq-haskell/-/issues/66</a>
[3] <a class="gmail-moz-txt-link-freetext" href="https://gitlab.com/twittner/zeromq-haskell/-/merge_requests/6">https://gitlab.com/twittner/zeromq-haskell/-/merge_requests/6</a>
[4] <a class="gmail-moz-txt-link-freetext" href="https://github.com/gibiansky/IHaskell">https://github.com/gibiansky/IHaskell</a>
</pre>
      <br>
      <fieldset class="gmail-mimeAttachmentHeader"></fieldset>
      <pre class="gmail-moz-quote-pre">_______________________________________________
ghc-devs mailing list
<a class="gmail-moz-txt-link-abbreviated" href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a>
<a class="gmail-moz-txt-link-freetext" href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a>
</pre>
    </blockquote>
  


</div></div>