type synonyms for dynamic imports and wrappers

Eric Mertens emertens at gmail.com
Thu Aug 18 15:34:46 UTC 2016


On Aug 18, 2016, at 8:17 AM, Henning Thielemann <lemming at henning-thielemann.de> wrote:
> 
> 
> The Haskell FFI report says that imports and exports of dynamic functions always have those types:
> 
> foreign import ccall "dynamic"
>  mkFun :: FunPtr fun -> fun
> 
> foreign import ccall "wrapper"
>  mkCallback :: fun -> IO (FunPtr fun)
> 
> where 'fun' is an IO function. Since 'fn' can be a considerably large type expression I usually define
> 
> type Importer fun = FunPtr fun -> fun
> type Exporter fun = fun -> IO (FunPtr fun)

I’d enjoying having these available in base. Beyond the convenience of not having to define them myself I think that they help people to understand how wrapper and dynamic imports are intended to be used. I’ve certainly helped people on IRC with these kinds of imports and seen that the required shape of them can be confusing. This type synonyms would provide a good place to anchor some documentation.

I typically name them Dynamic and Wrapper when I use them just to match the FFI syntax. Importer and Exporter could be more obvious names. (Having Dynamic added to base would obviously conflict with Data.Dynamic)

Regards,
Eric Mertens


More information about the Libraries mailing list