<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Friends<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Short summary: <b>can someone familiar with using the GHC API offer advice on getting the Wolfram Language connected to Haskell</b>?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Many of you will know of the
<a href="https://www.wolfram.com/language/">Wolfram Language</a>, which is IMHO pretty cool and not well enough known.    There are lots of interesting things about it, but a huge thing is that it’s deeply connected to the vast pile of carefully curated data
 that Wolfram Research has gathered and organised over several decades.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Anyway, they’d like to be able to invoke Haskell code from the Wolfram Language interpreter.   But as you’ll see below, they are understandably stumbling on the engineering aspects of doing so.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Rather than spam Stephen Wolfram himself, I’m cc’ing Todd Gayley who is the team lead.  (Hi Todd.)   I’d really appreciate it if some of you could help advise him.  It would be terrific to have a
 direct connection between Wolfram and Haskell!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Many thanks<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Simon<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> Stephen Wolfram
<br>
<b>Sent:</b> 01 April 2020 01:49<br>
<b>To:</b> Simon Peyton Jones <simonpj@microsoft.com><br>
<b>Subject:</b> Haskell question, etc.<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">        <br>
<br>
Simon ---<br>
<br>
[…snip…]<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">What brings me to email is a Haskell question:<br>
<br>
It's probably best that I just forward what my team wants to ask:<br>
<br>
=========<br>
<br>
A powerful feature of the Wolfram Language is that it allows users to evaluate code in other programing languages, returning the results to a Wolfram notebook (<a href="https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Freference.wolfram.com%2Flanguage%2Fguide%2FExternalInterpretedLanguageInterfaces.html&amp;data=02%7C01%7Csimonpj%40microsoft.com%7Cb8abce5772944182a1de08d7d5d68940%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637212989714565411&amp;sdata=po6qg70bq8f4jbEvTRv6eoQfhLSZ3Fvdj3DBJFpWB%2FY%3D&amp;reserved=0">https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Freference.wolfram.com%2Flanguage%2Fguide%2FExternalInterpretedLanguageInterfaces.html&amp;data=02%7C01%7Csimonpj%40microsoft.com%7Cb8abce5772944182a1de08d7d5d68940%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637212989714565411&amp;sdata=po6qg70bq8f4jbEvTRv6eoQfhLSZ3Fvdj3DBJFpWB%2FY%3D&amp;reserved=0</a>).
 We have implemented this feature for a number of languages, including Python, NodeJS, Julia, and Ruby. We would very much like to include Haskell in this set, but we have little Haskell expertise, and have hit a stumbling block. We would appreciate it if some
 Haskell experts could help us out with this feature.<br>
<br>
We have the following basic line of code for evaluating a string of Haskell code:<br>
<br>
    r <- liftIO $ runInterpreter $ do { setImports ["Prelude"]; eval strToEvaluate}<br>
<br>
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.<br>
<br>
The basic flow of our functionality is as follows:<br>
<br>
1) User calls StartExternalSession["LanguageName"] to launch an interpreter for the language. This process remains running and can be used for multiple calls.<br>
<br>
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.)<br>
<br>
ZeroMQ is used as the transport between Wolfram Language and the external language interpreter, and JSON is the data format we use to return results. Beyond the basics of hooking up GHCi for this type of session use, we also would like assistance in introspection
 of Haskell results so that they can be sent back to WL in the most useful form. This is the general structure of what we do for other languages:<br>
<br>
     if result is an object<br>
         return object data<br>
     else if result is a function<br>
         return function data<br>
     else<br>
        return JSON form of the expression<br>
<br>
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.<br>
<br>
<br>
========<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><br>
<br>
<br>
Any help greatly appreciated!  (Not least because I'd personally like to play with this... :) )<br>
<br>
--- Stephen<br>
<br>
<o:p></o:p></p>
</div>
</div>
</div>
</body>
</html>