
On Wednesday 29 March 2006 01:35, Bulat Ziganshin wrote:
primitives work with just the same internal structures. i thinl that only real advantage of adding primop instead of adding FFI import is that PrimOps.cmm contains already implemented wrappers for calling GMP functions while for FFI you should implement them from scratch
Hello, You could very well be right. In fact, the main advantage that I see of solving my problem by adding a new GHC primitive operation is simply that this solution worked for me. I have so far not been able to concoct another solution that uses FFI. Quite possibly for simple lack of insight. But the "adding a new primitive operation"-method is not, of course, without its disadvantages. For example, now I have some additional work whenever I wish to use a new GHC version. And I also have to become fluent in generating GHC for Windows, because I also use the Windows version. All in all, I have not at all given up the idea of solving my problem of interfacing directly with the GMP functions using the FFI. But, as I have said, I have not been able to come up with such a solution. But perhaps you can help me out here. Suppose, for the example, that I wish to call the mpz_gcdext function. That function takes two integers as input and returns three. Here are some questions: 1. How should I declare the C (wrapper) function in Haskell? 2. What would a call of this function look like? 3. What circumstances would the implementing C (wrapper) function have to deal with? In particular, how would it access the two Integer input parameters? And how would it return the resulting three Integer results? I should tell you that I have studied the FFI document "The Haskell 98 Foreign Function Interface 1.0 An Addendum to the Haskell 98 Report (Release Candidate 14)" in detail, not finding it particularly easy going. I am also familiar with the properties of the FFI as implemented by GHC. In fact, I have tried to call a (very simple) C function from Haskell and it actually worked. Unfortunately, the solution to the main problem, that of passing Haskell Integer typed values back and forth between Haskell and C, still eludes me. (I have also seen Simon Marlow's comments to your letter. The sort of things that he talks about there ring bells, sure, but the details are completely unknown to me.) Thank you very much for any help that you provide in this matter. Regards Thorkil