Connecting the Wolfram Language to Haskell

Compl Yue compl.yue at
Tue May 5 17:39:13 UTC 2020


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

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

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

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.

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.






On 2020/5/1 上午5:13, Ben Gamari wrote:

Simon Peyton Jones via ghc-devs <ghc-devs at>
<ghc-devs at> writes:


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

Hi Todd, et al.,

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


We have the following basic line of code for evaluating a string of
Haskell code:

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

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.

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.

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,



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.

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.


- Ben


ghc-devs mailing
listghc-devs at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the ghc-devs mailing list