[Haskell-cafe] Dynamically find out instances of classes (pluginsystem for haskell)

Andrew Coppin andrewcoppin at btinternet.com
Thu Nov 22 14:33:08 EST 2007


Claus Reinke wrote:
>> I hope this is understandable what I'm trying to achieve here.
>
> not really: the only classes in haskell are type classes, and
> if there is any class instance missing at compile time, you
> won't even get to runtime, so you don't have to worry
> about loading instances at runtime!-)
>
> perhaps you could describe the problem you are trying
> to solve, rather than the solution you would like to see?

In [gasp!] Java, you can just stick compiled files into a folder, and 
write your main program such that ts scans this folder, loads anything 
it finds, and executes specific code within it. In other words, an 
instant plugin system. I imagine this is what the original poster is after.

I'm not 100% sure, but I think hsplugins can dynamically load compiled 
*.o files in this way. Not sure whether this requires the person running 
the main program to have GHC installed though.

Unlike Java, there's no reflection capabilities. This isn't too bad 
though; just write your own class definition to allow your main program 
to query the thing it just loaded and find out what it offers.

  class Describable d where
    available_functions :: d -> [FunctionInfo]

  data FunctionInfo = FunctionInfo {name :: String, description :: 
String, ...}

Unlike general reflection (where you try to guess things from function 
names and so on), this can be taylored to exactly the kind of plugins 
you're trying to write.



More information about the Haskell-Cafe mailing list