RE: [Haskell-cafe] Dynamically find out instances of classes (pluginsystem for haskell)
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Radoslaw Grzanka Hi, Is there any plugin system for haskell? For example, in Java, I can load all compiled classes from given directory, check their interfaces and run some methods through reflection etc. Is it possible in haskell, to load modules from given directory, and if in module there is instance of class then return instantiation of that class? There are two libs that I'm aware of. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/plugins-1.0 http://hackage.haskell.org/cgi-bin/hackage-scripts/package/metaplug-0.1. 1 AFAICT, plugins is more mature and has a higher-level API, but the last time I looked it was not working on Windows under ghc = 6.6 (can anyone refute or verify this?) It's more like dynamic linking than Java's reflection: you have to already know what functions are in the module (and their types) to be able to call them. I'm not sure about directly creating values of data types exported from the module. Alistair * Confidentiality Note: The information contained in this message, and any attachments, may contain confidential and/or privileged material. It is intended solely for the person(s) or entity to which it is addressed. Any review, retransmission, dissemination, or taking of any action in reliance upon this information by persons or entities other than the intended recipient(s) is prohibited. If you received this in error, please contact the sender and delete the material from any computer. * ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Dynamically find out instances of classes (pluginsystem for haskell)
Hi, Thanks for answer. There are two libs that I'm aware of. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/plugins-1.0 http://hackage.haskell.org/cgi-bin/hackage-scripts/package/metaplug-0.1. 1 Unfortunatly former needs gcc, latter does not compile . I will have to install msys or something I guess It's more like dynamic linking than Java's reflection: you have to already know what functions are in the module (and their types) to be able to call them. I'm not sure about directly creating values of data types exported from the module. I know the types - not a problem. I just don't know the names. Thanks, Radek. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Dynamically find out instances of classes (pluginsystem for haskell)
Is there any plugin system for haskell? For example, in Java, I can load all compiled classes from given directory, check their interfaces and run some methods through reflection etc. Is it possible in haskell, to load modules from given directory, and if in module there is instance of class then return instantiation of that class? 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 general, ghci and hugs allow you to browse your modules, find out types and names, run tests, etc. ghci can be scripted to some extent (not always comfortably, but possibly sufficient if you only want to find and run all functions named test*, for instance), and if that isn't enough, ghc has an api that allows you to program your own variant of ghci, among other things. claus ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Dynamically find out instances of classes (pluginsystem for haskell)
2007/11/22, Claus Reinke [EMAIL PROTECTED]: Is there any plugin system for haskell? For example, in Java, I can load all compiled classes from given directory, check their interfaces and run some methods through reflection etc. Is it possible in haskell, to load modules from given directory, and if in module there is instance of class then return instantiation of that class? 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!-) Maybe I wasn't clear enough, maybe It is too much OO, maybe this is exploiting language, maybe there are better ways. ;) Let's say that in common module I have declaration (written from head, so may not compile - only for illustration) class Foo a where fun :: a - String This is my interface declaration. Now in seperate modules I have: data GreatFooInstance = GreatFooInstance instance Foo GreatFooInstance where fun a = 1 in another module I have data GreatFooInstance' = GreatFooInstance' instance Foo GreatFooInstance' where fun a = 2 at my main program I want to load all modules from directory and receive a structure of (lack of vocabluary here) instantiated instances of the class like this: l :: Foo a = [a] l = [GreatFooInstance, GreatFooInstance'] This above is illegal in haskell I believe, so some other approach should be taken. The question is what is correct way (if any) to handle this. But if it was legal then the usage might be like: o = map foo l I cannot be more specifc because this is just theory, I'm playing with haskell to know it features and limits. The key here is to add and remove modules and find the list of modules at runtime, load it and (with known interface) call its functions. Hope it is clear enough now. Thanks, Radek. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Dynamically find out instances of classes (pluginsystem for haskell)
Bayley, Alistair-2 wrote: There are two libs that I'm aware of. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/plugins-1.0 http://hackage.haskell.org/cgi-bin/hackage-scripts/package/metaplug-0.1. 1 There is also http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hint-0.1 I managed to install it (though not without some hassle, i.e. having to use multiple Cabal versions), and make simple examples work. -- Grzegorz -- View this message in context: http://www.nabble.com/Dynamically-find-out-instances-of-classes-%28plugin-system-for-haskell%29-tf4855053.html#a13897174 Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Dynamically find out instances of classes (pluginsystem for haskell)
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. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Dynamically find out instances of classes (pluginsystem for haskell)
I'm not 100% sure, but I think hsplugins can dynamically load compiled *.o files in this way. Correct. Not sure whether this requires the person running the main program to have GHC installed though. Yes, it does. Thanks ciao, Leif 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. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe