Re: [Haskell-cafe] Injecting Haskell into C
you'll find this example really helpfull ---------- Forwarded message ---------- From: Claude Heiland-Allen <claudiusmaximus@goto10.org> Date: 2008/6/5 Subject: Re: [Haskell-cafe] example of FFI FunPtr To: "Galchin, Vasili" <vigalchin@gmail.com> Cc: haskell <haskell-cafe@haskell.org> Galchin, Vasili wrote:
Hello,
I want to model a Haskell function that is a callback from C. I have only found one example in the unix package's Semaphore.hsc, which apparently is not used. I want to be able to marshall a Haskell function that is a first class citizen residing in a Haskell data type and pass to a C function via FFI. Are there examples of this?
Attached is a simple example. The main thing to note is 'foreign import ccall "wrapper"' which gives you a factory for turning Haskell functions into foreign function pointers. More information: http://www.cse.unsw.edu.au/~chak/haskell/ffi/ Claude -- http://claudiusmaximus.goto10.org CallBacker: CallBacker.hs callerback.c callerback.h ghc -O2 -Wall -fffi -o CallBacker CallBacker.hs callerback.c _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Anatoly I have not been following the details, but would you consider writing up your example on the GHC user guide Wiki? http://haskell.org/haskellwiki/GHC/Using_the_FFI It's a very good way to share your experience with others. Simon | -----Original Message----- | From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe- | bounces@haskell.org] On Behalf Of Anatoly Yakovenko | Sent: 24 September 2008 22:42 | To: roma@ro-che.info | Cc: haskell | Subject: Re: [Haskell-cafe] Injecting Haskell into C | | you'll find this example really helpfull | | | ---------- Forwarded message ---------- | From: Claude Heiland-Allen <claudiusmaximus@goto10.org> | Date: 2008/6/5 | Subject: Re: [Haskell-cafe] example of FFI FunPtr | To: "Galchin, Vasili" <vigalchin@gmail.com> | Cc: haskell <haskell-cafe@haskell.org> | | | Galchin, Vasili wrote: | > | > Hello, | > | > I want to model a Haskell function that is a callback from C. I have | > only found one example in the unix package's Semaphore.hsc, which | apparently | > is not used. I want to be able to marshall a Haskell function that is a | > first class citizen residing in a Haskell data type and pass to a C | function | > via FFI. Are there examples of this? | | Attached is a simple example. | | The main thing to note is 'foreign import ccall "wrapper"' which gives | you a factory for turning Haskell functions into foreign function | pointers. | | More information: | | http://www.cse.unsw.edu.au/~chak/haskell/ffi/ | | | Claude | -- | http://claudiusmaximus.goto10.org | | | CallBacker: CallBacker.hs callerback.c callerback.h | ghc -O2 -Wall -fffi -o CallBacker CallBacker.hs callerback.c | | _______________________________________________ | Haskell-Cafe mailing list | Haskell-Cafe@haskell.org | http://www.haskell.org/mailman/listinfo/haskell-cafe
I have not been following the details, but would you consider writing up your example on the GHC user guide Wiki? http://haskell.org/haskellwiki/GHC/Using_the_FFI
It's a very good way to share your experience with others.
I got that example from Claude Heiland-Allen. Unless he has any objections, or would like to do it himself, I can put it on the wiki. Anatoly
I have not been following the details, but would you consider writing up your example on the GHC user guide Wiki? http://haskell.org/haskellwiki/GHC/Using_the_FFI
It's a very good way to share your experience with others.
I got that example from Claude Heiland-Allen. Unless he has any objections, or would like to do it himself, I can put it on the wiki.
actually, its already on there, http://haskell.org/haskellwiki/GHC/Using_the_FFI#Callbacks_into_Haskell_from...
Anatoly
participants (2)
-
Anatoly Yakovenko -
Simon Peyton-Jones