Sylvain HENRY | 2 Aug 18:08 2012
Picon

[ANNOUNCE] dynamic-linker-template: automatically derive dynamic linking methods from a data type.

Hi,

A few days ago I uploaded on Hackage the first release of 
dynamic-linker-template package (System.Posix.DynamicLinker.Template). 
Basically, it uses Template Haskell to generate boilerplate code to 
dynamically load symbols of a shared library into a data defined using 
"record" syntax.

Simple example:

----------------------
{-# LANGUAGE TemplateHaskell, ForeignFunctionInterface #-}

import System.Posix.DynamicLinker.Template

data MyLib = MyLib {
     -- Mandatory field (name and type)
     libHandle :: DL,

     -- Mandatory symbol. Will throw an exception if not available
     myFunction1 :: Int -> Float,

      -- Optional symbol
     myFunction2 :: Maybe (Int -> Int)
}

$(makeDynamicLinker ''MyLib CCall 'id)

-- Use any String->String function instead of "id" to transform field 
names into symbol names
(Continue reading)


Gmane