Opened 5 years ago

Last modified 13 months ago

#7048 new feature request

Add the ability to statically define a `FunPtr` to a haskell function

Reported by: pcapriotti Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.4.2
Keywords: Cc: la@…, iavor.diatchki@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


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.

Change History (7)

comment:1 Changed 5 years ago by simonpj

Cc: la@… added

Adding Lauri to the cc list, since he originated the proposal.

comment:2 Changed 5 years ago by diatchki

Cc: iavor.diatchki@… added

I implemented something like that a couple of years ago so I think this would be a useful feature. The old thread on the topic is here:

comment:3 Changed 5 years ago by simonmar

Thanks Iavor. I just skimmed that thread. Your static_wrapper idea is indeed similar, but not quite the same. The proposed extension here differs from static_wrapper in two ways:

  • It doesn't have an implicit StablePtr argument built-in
  • It doesn't imply the creation of a C symbol

comment:4 Changed 3 years ago by thoughtpolice


Moving to 7.10.1.

comment:5 Changed 2 years ago by thoughtpolice


Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

comment:6 Changed 18 months ago by thoughtpolice


Milestone renamed

comment:7 Changed 13 months ago by thomie

Milestone: 8.0.1
Note: See TracTickets for help on using tickets.