Add the ability to statically define a `FunPtr` to a haskell function
Lauri Alanko suggests that there should be a way to define a callback to a haskell function statically (i.e. without using a dynamic wrapper).
It is currently possible to do so only by exporting the function and reimporting it as a function pointer:
foreign export ccall "my_callback" myCallback :: IO ()
foreign import ccall "&my_callback" myCallbackPtr :: FunPtr (IO ())
but of course this not ideal because it creates an extra symbol (and is quirky).
A possible new syntax could be:
foreign import ccall myCallbackPtr :: FunPtr (IO ()) = myCallback
or variations thereof. We probably want to keep import
(rather than export
or some new keyword), since this declaration brings something into scope, like a normal FFI import.
Trac metadata
Trac field | Value |
---|---|
Version | 7.4.2 |
Type | FeatureRequest |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |