type synonyms for dynamic imports and wrappers

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) How about adding these type synonyms to Foreign?

On Aug 18, 2016, at 8:17 AM, Henning Thielemann
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
participants (2)
-
Eric Mertens
-
Henning Thielemann