Opened 3 years ago

Last modified 9 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: 7.12.1
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 Revisions:

Description

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 (5)

comment:1 Changed 3 years ago by simonpj

  • Cc la@… added

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

comment:2 Changed 3 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:

http://www.haskell.org/pipermail/glasgow-haskell-users/2010-March/018575.html

comment:3 Changed 3 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 17 months ago by thoughtpolice

  • Milestone changed from 7.8.3 to 7.10.1

Moving to 7.10.1.

comment:5 Changed 9 months ago by thoughtpolice

  • Milestone changed from 7.10.1 to 7.12.1

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.

Note: See TracTickets for help on using tickets.