Chris Angus wrote:
>
> Put simply
>
> What do people think about being able to access functions from other modules
> without
> importing the module.
>
> i.e. Rather than
>
> ---------------Start-------------
> import Foo
> -- call f
> callFoof x = f x
> --------------End----------------
>
> We can do
>
> ---------------Start-------------
> callFoof x =
> case (getFunction "Foo.f" (bot::Int -> Int) ) of
> (Just f) -> f x
> (nothing) -> error "Foo not linked in"
> ---------------End---------------
My first reaction is "ugh" but on further consideration it is at least
an intriguing idea. But I think the syntax is wrong. Perhaps you could
have something like this:
loadModule :: String -> IO Module
-- dynamically load module, or raise some
-- sort of exception
lookupName :: Module -> String -> IO a -- lookup name or give exception
Then code might look like
do
fooModule <- loadModule "Foo"
fooF <- (lookupName fooModule "f") :: IO (Int -> Int)
. . .
lookupName would need to be a special compiler primitive and there would
need to be special compiler magic to pass the most general possible type
for its result to the RTS. For example
applyFooF x =
do
fooF <- lookupName fooModule "f"
return (fooF x)
might have to fail except in the unlikely case that Foo.f turned out to
have type (for all a,b) ( a -> b ).