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

Reply via email to