Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I create an extensible (through additional custom plugins) application on Haskell?

Tags:

haskell

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.

like image 489
Andrey Bushman Avatar asked Feb 05 '15 07:02

Andrey Bushman


2 Answers

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.

like image 93
Frédéric Dumont Avatar answered Nov 10 '22 19:11

Frédéric Dumont


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

like image 24
Chris Emerson Avatar answered Nov 10 '22 18:11

Chris Emerson