[Haskell-cafe] Anonymous FFI calls
Sylvain Henry
hsyl20 at gmail.com
Fri Feb 13 18:28:25 UTC 2015
Hi,
The FFI pages on the wiki are not really in a good shape in my opinion
(especially for newcomers).
I have started a fresh one here:
https://wiki.haskell.org/Foreign_Function_Interface_(FFI)
This is just the first draft. I will improve it, probably split it in
several pages and merge information from other pages, especially pages
linked on https://wiki.haskell.org/FFI
Sylvain
2015-02-12 10:02 GMT+01:00 Simon Peyton Jones <simonpj at microsoft.com>:
> | Thanks to everyone who replied!
> |
> | It seems like that through a combination of facilities like `libffi'
> | and `addTopDecls' I can do everything that I wanted to do.
>
> Great. But please, please, do write up what you learned on the FFI wiki
> page
> https://wiki.haskell.org/GHC/Using_the_FFI
>
> Simon
>
> | -----Original Message-----
> | From: Francesco Mazzoli [mailto:f at mazzo.li]
> | Sent: 12 February 2015 09:00
> | To: Simon Peyton Jones
> | Cc: Michael Sloan; Manuel Chakravarty; Geoffrey Mainland
> | (mainland at cs.drexel.edu); ghc-devs at haskell.org; haskell
> | Subject: Re: [Haskell-cafe] Anonymous FFI calls
> |
> | Thanks to everyone who replied!
> |
> | It seems like that through a combination of facilities like `libffi'
> | and `addTopDecls' I can do everything that I wanted to do.
> |
> | I still want to take a shot at implementing anonymous FFI calls, since
> | IMHO I think they are a very small but useful addition to the
> | language.
> |
> | Francesco
> |
> | On 12 February 2015 at 09:29, Simon Peyton Jones <simonpj at microsoft.com>
> | wrote:
> | > | Also, I meant to say that addTopDecls is only exported by
> | > | "Language.Haskell.TH.Syntax". While this is a digression, there are
> | a
> | > | few other handy functions that are oddly left out of
> | > | "Language.Haskell.TH": addDependentFile, addModFinalizer, and
> | possibly
> | > | more.
> | >
> | > That does seem wrong. Do make a patch!
> | >
> | > SIMon
> | >
> | > |
> | > | -Michael
> | > |
> | > | On Wed, Feb 11, 2015 at 3:25 PM, Simon Peyton Jones
> | > | <simonpj at microsoft.com> wrote:
> | > | > I would LOVE someone to improve the documentation for addTopDecls.
> | > | Manuel Chakravarty and Geoff Mainland were responsible for the
> | > | implementation.
> | > | >
> | > | > Simon
> | > | >
> | > | > | -----Original Message-----
> | > | > | From: ghc-devs [mailto:ghc-devs-bounces at haskell.org] On Behalf
> | Of
> | > | > | Michael Sloan
> | > | > | Sent: 11 February 2015 23:19
> | > | > | To: Francesco Mazzoli
> | > | > | Cc: ghc-devs at haskell.org; haskell
> | > | > | Subject: Re: [Haskell-cafe] Anonymous FFI calls
> | > | > |
> | > | > | It seems like addTopDecls[1] will able to help here.
> | > | Unfortunately,
> | > | > | the function is not well documented and not very discoverable
> | > | > | because it's only exported by Language.Haskell.TH.
> | > | > |
> | > | > | The documentation doesn't mention that it can only be used to
> | > | create
> | > | > | new top level functions and FFI imports[2]. I think that adding
> | > | FFI
> | > | > | imports was the main motivation for implementing it. In the
> | past
> | > | > | I've wanted to generate instances via this function, but
> | > | > | unfortunately it's not implemented..
> | > | > |
> | > | > | Hope that helps!
> | > | > | -Michael
> | > | > |
> | > | > | [1] http://hackage.haskell.org/package/template-haskell-
> | > | > | 2.9.0.0/docs/Language-Haskell-TH-Syntax.html#v:addTopDecls
> | > | > |
> | > | > | [2]
> | > | > |
> | > |
> https://github.com/ghc/ghc/blob/1d982ba10f590828b78eba992e73315dee33
> | > | > | f78a/
> | > | > | compiler/typecheck/TcSplice.hs#L818
> | > | > |
> | > | > | On Wed, Feb 11, 2015 at 2:26 AM, Francesco Mazzoli <f at mazzo.li>
> | > | wrote:
> | > | > | > Hi,
> | > | > | >
> | > | > | > I am in a situation where it would be very useful to call C
> | > | > | > functions without an explicit FFI import. For example, I'd
> | like
> | > | > | > to be able to do
> | > | > | >
> | > | > | > (foreign import ccall "cadd" :: CInt -> CInt -> CInt) 1 2
> | > | > | >
> | > | > | > instead of declaring the foreign import explicitely at the top
> | > | level.
> | > | > | >
> | > | > | > Is there a way to do this or to achieve similar results in
> | some
> | > | > | > other way?
> | > | > | >
> | > | > | > If not, I imagine it would be easy to implement such a
> | facility
> | > | in
> | > | > | > GHC, given that the code implementing calling to C functions
> | > | must
> | > | > | > already be present to implement "proper" FFI imports. I think
> | > | > | > such an addition would be useful in many cases.
> | > | > | >
> | > | > | > Thanks,
> | > | > | > Francesco
> | > | > | > _______________________________________________
> | > | > | > Haskell-Cafe mailing list
> | > | > | > Haskell-Cafe at haskell.org
> | > | > | > http://www.haskell.org/mailman/listinfo/haskell-cafe
> | > | > | _______________________________________________
> | > | > | ghc-devs mailing list
> | > | > | ghc-devs at haskell.org
> | > | > | http://www.haskell.org/mailman/listinfo/ghc-devs
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at haskell.org
> http://www.haskell.org/mailman/listinfo/ghc-devs
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/ghc-devs/attachments/20150213/0d9c99ce/attachment-0001.html>
More information about the ghc-devs
mailing list