dynamic-loader-0.0.1: lightweight loader of GHC-based modules or packages

Copyright(c) Hampus Ram 2004 Gabor Greif 2012
LicenseBSD-style (see LICENSE)
Portabilitynon-portable (ghc >= 7.6 only)
Safe HaskellNone



A module that implements dynamic loading. Has smart handling of dependencies and is thread safe.



setBasePath :: Maybe FilePath -> IO () Source #

Set the base path used in figuring out module names. If not set the default (i.e. currentDirectory) will be used.

addDependency :: FilePath -> (ModuleType, FilePath) -> IO () Source #

Add a module dependency. Any dependencies must be added before any calls to loadModule/loadPackage or symbols will not be resolved with a crash as result.

setDependencies :: FilePath -> [(ModuleType, FilePath)] -> IO () Source #

Set all dependencies. All previous dependencies are removed.

delDependency :: FilePath -> (ModuleType, FilePath) -> IO () Source #

Delete a module dependency.

delAllDeps :: FilePath -> IO () Source #

Delete all dependencies for a module. Same behaviour as setDependencies path [].

withDependencies :: Loadable c t t' => Criterion c t -> FilePath -> (Maybe [(ModuleType, FilePath)] -> Effective c t) -> Effective c t Source #

Do something with the current dependencies of a module. You can't use (blocking) functions from this module in the function given to withDependencies. If you do so, a deadlock will occur.

loadModule :: FilePath -> ModuleType -> IO LoadedModule Source #

Load a module (or package) and modules (or packages) it depends on. It is possible to load a module many times without any error occuring. However to unload a module one needs to call unloadModule the same number of times.

Before loading any modules you should add wich dependencies it has with addDependency (and which dependencies the modules upon which it depends have).

If the module already has been loaded nothing will be done except updating the reference count. I.e. if dependencies have been updated they will be ignored until the module has been completely unloaded and loaded again.

If any error occurs an exception is thrown.

unloadModule :: LoadedModule -> IO () Source #

Unload a module and all modules it depends on. This unloading only occurs if the module isn't needed by any other libraries or hasn't been loaded more than once. An exception is thrown in case of error.

unloadModuleQuiet :: LoadedModule -> IO () Source #

Same as unloadModule just doesn't trow any exceptions on error.

loadFunction :: Loadable c t t' => Criterion c t -> LoadedModule -> String -> Effective c t Source #

Load a function from a module. It cannot load functions from packages and will throw an exception if one tries to do so. Also throws if an error occurs.

It seems (but I'm unsure) like any functions loaded will continue to be valid even after the module it resides in is unloaded. It will also still be valid if a new version of that module is loaded (it will thus still call the old function).

loadQualifiedFunction :: Loadable c t t' => Criterion c t -> String -> Effective c t Source #

Load a qualified function from a module or package. It will throw an exception if an error occurs. Same restriction as for DynamicLinker.loadQualifiedFunction applies here too.

moduleLoadedAt :: LoadedModule -> IO UTCTime Source #

Give the modification time for a loded module. Will throw an exception if the module isn't loaded.

addDLL :: String -> IO () Source #

Dynamically load a shared library (DLL or .so). A shared library can't be unloaded using this interface, if you need it use System.Posix.DynamicLinker instead.