<div dir="auto"><p dir="ltr">> what would be *really* useful would be if importing was in some sense “just a function” in IO or some other Monad and therefore also if modules were represented as some Haskell data structure.</p>
<p dir="ltr">You can do something like this using the GHC API. A program that depends on the `ghc` library can parse and compile a module, and then look up module bindings by name and (unsafely) coerce them into normal values. See `hint` (<a href="https://hackage.haskell.org/package/hint">https://hackage.haskell.org/package/hint</a>) for some inspiration.</p>
<p dir="ltr">I was playing around with this sort of thing because I wanted to use Haskell modules as plugins for a program that I wrote. I got it working - the program could load and run the plugin module - but decided to go back to a fraught stringly-typed interface between two separately compiled processes.</p><p dir="ltr">One reason was that the dynamic loading approach was too slow, and I wasn't interested in figuring out how to make it faster.</p><p dir="ltr">Another reason was that my program is intended for use in certain Haskell projects, and it's unlikely that the GHC compiler embedded in the program will match the version that the user has for their project. I didn't want to allow the user to write code that compiles with their GHC but not when loaded into my program (e.g. if their GHC version is newer and they use a new feature).</p></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 5 Dec 2024, 03:08 Brandon Allbery, <<a href="mailto:allbery.b@gmail.com">allbery.b@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr">On Wed, Dec 4, 2024 at 9:31 AM julian <a href="http://getcontented.com.au" target="_blank" rel="noreferrer">getcontented.com.au</a> <<a href="mailto:julian@getcontented.com.au" target="_blank" rel="noreferrer">julian@getcontented.com.au</a>> wrote:</div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">One of the things a little strange about the programming industry is how quick we are to invent entirely new languages rather than attempt to modify existing ones and beat them into a new more flexible shape so we can shoehorn our new requirements into a more flexible frame. I realise it’s not always possible, but surely if we all got together and worked on it we could do it?<br></blockquote><div><br></div><div>Generally at the price of breaking backward compatibility, which is already a major issue with GHC and would get much worse here.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">It would be *glorious* if stack (or cabal, or whatever package manager we use) itself were programmable in the sense that it could be called from within Haskell itself using a typed API and data could drive its included packages, and its type could be a function whose range was IO ByteString, providing the compiled binary.<br></blockquote><div><br></div><div>The Cabal library is already largely programmable in this sense, although as it drives system tools you have the problem that inputs and outputs are disk files coming from or going to those tools. Changing this requires changing the system tools, or reimplementing them which would be prohibitively difficult and subject to regular breakage.</div><div><br></div></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>brandon s allbery kf8nh</div><div><a href="mailto:allbery.b@gmail.com" target="_blank" rel="noreferrer">allbery.b@gmail.com</a></div></div></div></div></div></div>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div>