I learn Haskell.
When I wrote my applications on C#, I did it extensible. I.e. it can be extended through loading of additional, custom DLL files (plugins or extensions - it is the same). My managed application through the Reflection
mechanism find the necessary classes and methods by their some attributes and registers them in the common command registry of my application. But I can to do it because .NET Framework has the Reflection
technology. So I can extend the functional the base of my application without recompiling it.
Can I create an extensible (through additional custom plugins) application on Haskell? Has Haskell the mechanism is similar of Reflection
by .NET Framework? Or maybe exists other way to do the same in Haskell.
There is a GHC library to dynamically load plugins. There is also some support for a kind of introspection, but that is not really the Haskell way.
What you can do instead is to add a register-plugin
function of a predefined type to each plugin, then call that function when you load the plugin. The function being part of the plugin can have as much knowledge of the plugin as required, and needs no introspection. The main code does not need to know anything about the plugin beside the type of the register-function
.
Note that this works in other languages without introspection as well, for instance in C.
I guess it may not quite work for you, [XMonad][1] takes a different approach. The configuration file is a Haskell source file; when you change the configuration and ask to reload it recompiles itself and restarts. (It's basically seamless).
[1]: http://xmonad.org/ XMonad
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With