<p dir="ltr">I've been pondering how feasible it would be to:</p>
<p dir="ltr">* Compile in stages a module with the byte code linker<br>
* Keep hold of the Core source<br>
* Interpret the Core AST within Haskell<br>
* When encountering built-in/primitives (or things from other libraries), we compile that Core term and link it as an HValue and then run it with the arguments expected. So () would be such a HValue, as would be "show" which in interpretable unoptimized Core would take an extra argument for the Show instance. When passing in values to such "foreign" functions it would wrap them up in an interpretive way. </p>
<p dir="ltr">This is the hypothetical idea, it seems like it would yield a really trivial way to write a new and interesting interpreter for GHC Haskell without having to re-implement any prim ops, ready to work on regular Haskell code.</p>
<p dir="ltr">In my case, I would use this to write an interpreter which:</p>
<p dir="ltr">* is not tagless, so we preserve type info<br>
* allows top-level names to be redefined<br>
* when a function is applied, it checks the type of its arguments</p>
<p dir="ltr">Both of these are pretty much necessary for being able to do in-place update of a running program while developing (a la Emacs or Smalltalk), and type tags let us throw a regular Haskell exception of type error, a la deferred type errors. It means in your running program, if you make a mistake or forget to update one part, it doesn't bring the whole program down with an RTS error or a segfault, maybe a handler in a thread (like a server or a video game) throws an exception and the developer just updates their code and tries again.</p>
<p dir="ltr">I'd love support for something like this, but I'd rather not have to re-create the world just to add this capability. Because it's really just conceptually regular interpreted GHC Haskell plus type tags and updating, it seems like it should be a small diff.</p>
<p dir="ltr">Any input into this? How far away is GHC's current architecture from supporting such a concept? </p>
<p dir="ltr">Ciao!</p>