[Haskell-cafe] plugins and cabal build

Michael Snoyman michael at snoyman.com
Wed Apr 27 07:14:52 CEST 2011


On Tue, Apr 26, 2011 at 4:56 PM, Andy Stewart <lazycat.manatee at gmail.com> wrote:
> Ivan Lazar Miljenovic <ivan.miljenovic at gmail.com> writes:
>
>> On 26 April 2011 04:57, Michael Snoyman <michael at snoyman.com> wrote:
>>> Hi all,
>>>
>>> I'm experimenting with using the plugins package for yesod devel
>>> server. The basic approach is to use cabal for building the object
>>> files, and then load them with plugins. I can get everything to work
>>> when I compile with "ghc --make", but I believe name mangling is
>>> getting in the way with the "cabal build" route. Can someone give some
>>> guidance on how to properly mangle the function names so that plugins
>>> can load them?
>>
>> I'm not sure if he reads this list, but Andy Stewart might know (and
>> I've CC'd him to this).
> Hi Ivan, sorry for late, too busy on Linux job.
>
> Yes, i have got hot-swap code work for Manatee
> (http://hackage.haskell.org/package/manatee)
>
> I used to use plugins, but i found it's buggy.
> So i use GHC-API wrote my own code at:
> https://patch-tag.com/r/AndyStewart/manatee-core/snapshot/current/content/pretty/Manatee/Core/Dynload.hs
>
> Michael, from your need, you just need read function `dynload`, other
> functions is write for Manatee framework.
>
> Let me explain function `dynload`:
>
>    dynload :: (String, String, [(String, HValue -> IO ())]) -> IO ()
>    dynload (filepath, moduleName, loadList) = ...
>
> First argument is FilePath that contain module.
> Second argument is moduleName you need scan.
> Third argument is tuple list that contain symbol you need load and
> callback function for symbol's HValue.
>
> Once function `dynload` find symbol in target module, it will use below code
> dynamic load new value:
>
>    (do
>        hValue <- compileExpr (moduleName ++ "." ++ symbolName)
>        liftIO $ loadFun hValue)
>
> function `compileExpr` will get the HValue of symbol, then use loadFun
> update HVaule in running program.
>
> The key is `HValue -> IO ()`, you need build TVar/IORef in your
> running program, once you got new HValue, you should write
> writeTVar/writeIORef in function `HValue -> IO ()` to update the value of
> TVar/IORef, then you can dynamic loading new value and don't need
> reboot.
>
> I have draw some picture to explain above framework:
> http://www.flickr.com/photos/48809572@N02/5304662424/in/photostream/lightbox/
>
> Michael, hope above will help you, good luck! :)
>
>  -- Andy
>

Hi Andy,

Thanks you for your very helpful reply. I still have your previous
advice on this subject in my "things to study" list. Looks like taking
the easy way out didn't work after all. Thanks for the great example
to work from, hopefully it will work out properly.

Michael



More information about the Haskell-Cafe mailing list