pdynload-0.0.3: pdynload is polymorphic dynamic linking library.







:: (String, String)

A tuple (symbolModule, symbol), specifying a symbol in module

symbolModule is a fully-qualified module name, ie "Data.List"

symbol is an unqualified symbol name, ie "reverse".

-> ([String], String)

A tuple (typModuleList, typ), specifying a type in module

typModuleList is list module name, ie ["Prelude"] , you can empty this list if type define in Prelude.

typ is an unqualified type name, ie "String -> String".

Note, type check maybe failed if typ can't found in module list typModuleList.

-> IO (Maybe a)

If the specified symbol is found, Just its value. Otherwise, Nothing.

Polymorphic dynamic loading.

Resolves the specified symbol to any given type. This means linking the package containing it if it is not already linked, extracting the value of that symbol, and returning that value.

Here has simplest demo for test:

 module Main where
 import System.Plugin
 import Unsafe.Coerce
 main = do
   val <- pdynload ("Prelude", "reverse") ([], "String -> String")
   let str = case val of
               Just v  -> (unsafeCoerce v :: String -> String) "hello"
               Nothing -> "Load failed."
   print str

Because pdynload check type at runtime, so don't afraid unsafeCoerce, it is perfect safety.