<div dir="ltr">Hi,
<div><br></div><div>I'm playing around with <a href="https://www.stackage.org/haddock/lts-9.0/ghci-8.0.2/GHCi-ObjLink.html">https://www.stackage.org/haddock/lts-9.0/ghci-8.0.2/GHCi-ObjLink.html</a> to see if I can come up with some sort of hot-loading/plugin system in Haskell. </div><div><br></div><div>I've managed to load a shared object (compiled from a Haskell source via -rdynamic) with the following code:</div><div><br></div><div><div> {-# LANGUAGE OverloadedStrings #-}</div><div> {-# LANGUAGE MagicHash, UnboxedTuples #-}</div><div> <br></div><div> module Main where</div><div> <br></div><div> import GHC.Exts ( addrToAny# )</div><div> import GHC.Ptr ( Ptr(..) )</div><div> import System.Info ( os, arch )</div><div> import Encoding</div><div> import GHCi.ObjLink</div><div> import Debug.Trace</div><div> <br></div><div> main :: IO ()</div><div> main = do</div><div> traceM "before initObjLinker"</div><div> initObjLinker</div><div> traceM "before loadObj"</div><div> loadObj "/Users/saurabhnanda/projects/test-plugins/test-plugins/app/PluginMarkup.o"</div><div> traceM "after loadObj"</div><div> <br></div><div> -- NOTE: I've hardcoded the symbol name that I obtained from running `symbols PluginMarkup.o`</div><div> sym <- lookupSymbol "PluginMarkup_foliage_info"</div><div> traceM "after lookupsymbol"</div><div> traceM (show sym)</div></div><div><br></div><div>I'm getting the following output, which mean that I'm probably getting the Ptr to the function.</div><div><br></div><div><div> before initObjLinker</div><div> before loadObj</div><div> after loadObj</div><div> after lookupsymbol</div><div> Just 0x0000000104be49a8</div></div><div><br></div><div>Question is, how do I run the function in the same Haskell environment/runtime? The underlying function is actually `foliage :: UtcTime -> Html`</div><div><br></div><div>The code is available at <a href="https://github.com/vacationlabs/hint-test/blob/dll/app/Main.hs">https://github.com/vacationlabs/hint-test/blob/dll/app/Main.hs</a> and the DLL is available at <a href="https://github.com/vacationlabs/hint-test/blob/dll/app/PluginMarkup.o">https://github.com/vacationlabs/hint-test/blob/dll/app/PluginMarkup.o</a></div><div><br></div><div>-- Saurabh.</div></div>