Re: [Haskell-cafe] FunPtr error?

2008-06-16 Thread Ryan Ingram
The simple explanation is because the FFI standard says so; primitive types wrapped in newtypes automatically get wrapped and unwrapped during FFI calls. See http://www.cse.unsw.edu.au/~chak/haskell/ffi/ffi/ffise3.html#x6-120003.2 ; the FFI uses renamed datatype to mean newtype. Consider the

Re: [Haskell-cafe] FunPtr error?

2008-06-14 Thread Galchin, Vasili
oops .. my bad ... If I change data Sigval = SivalInt Int to newtype Sigval = SivalInt Int OR data Sigval = SivalPtr (Ptr Char) to newtype Sigval = SivalPtr (Ptr Char). Why should newtype instead of a data type allow my test case to build? Vasili On Fri, Jun 13, 2008 at 10:59

Re: [Haskell-cafe] FunPtr error?

2008-06-13 Thread Galchin, Vasili
If I change data Sigval = SivalInt Int | SivalPtr (Ptr Char) to ... newtype Sigval = Sivalint Int | SivalPtr (Ptr Char) then my test case builds and links. ?? Regards, Vasili On Mon, Jun 9, 2008 at 11:01 PM, Galchin, Vasili [EMAIL PROTECTED] wrote: I have tried various things

Re: [Haskell-cafe] FunPtr error?

2008-06-10 Thread Galchin, Vasili
I have tried various things to no avail [EMAIL PROTECTED]:~/FTP/Haskell/unix-2.2.0.0/tests/timer$ runhaskell Setup.lhs build Preprocessing executables for Test-1.0... Building Test-1.0... [1 of 1] Compiling Main ( ./timer.hs, dist/build/timer/timer-tmp/Main.o ) ./timer.hs:22:0:

Re: [Haskell-cafe] FunPtr error?

2008-06-10 Thread Ryan Ingram
I'm not super experienced with the FFI (foreign function interface); I only used C types that you can get from #include HsFFI.h, like Word32. You might need to make Sigval an instance of Storable, or do some magic with ForeignPtrs. Good luck! :) -- ryan On 6/9/08, Galchin, Vasili [EMAIL

Re: [Haskell-cafe] FunPtr error?

2008-06-10 Thread Ryan Ingram
Also, if you always plan to partially apply your notification function and you just want a simple callback: void (*pCallbackFn)(void); You should be able to do something like this: type Callback = IO () foreign import ccall wrapper mkCallback :: Callback - IO (FunPtr Callback) You can then

Re: [Haskell-cafe] FunPtr error?

2008-06-09 Thread Galchin, Vasili
Thanks. Clause? regards, Vasili On Mon, Jun 9, 2008 at 12:54 AM, Bulat Ziganshin [EMAIL PROTECTED] wrote: Hello Vasili, Monday, June 9, 2008, 6:17:14 AM, you wrote: 1. standard place to import FunPtr from is Foreign.Ptr, not System.Posix 2. FunPtr is exported as abstract type, without

Re: [Haskell-cafe] FunPtr error?

2008-06-09 Thread Galchin, Vasili
In any case, what I want to do is store FunPtr in a data type and marshall into a C struct as a C function pointer. Vasili On Mon, Jun 9, 2008 at 1:24 AM, Galchin, Vasili [EMAIL PROTECTED] wrote: Thanks. Clause? regards, Vasili On Mon, Jun 9, 2008 at 12:54 AM, Bulat Ziganshin [EMAIL

Re: [Haskell-cafe] FunPtr error?

2008-06-09 Thread Ryan Ingram
type Notify = Sigval - IO () foreign import ccall wrapper mkNotify :: Notify - IO (FunPtr Notify) then main = do notifyFPtr - mkNotify notifyFunc -- rest of code here -- then, when you are done and nothing is referencing the pointer any more freeHaskellFunPtr notifyFPtr On

Re: [Haskell-cafe] FunPtr error?

2008-06-09 Thread Galchin, Vasili
Ryan, I tried but the compiler didn't seem to like the keyword import: [EMAIL PROTECTED]:~/FTP/Haskell/unix-2.2.0.0/tests/timer$ runhaskell Setup.lhs build Preprocessing executables for Test-1.0... Building Test-1.0... [1 of 1] Compiling Main ( ./timer.hs,

Re: [Haskell-cafe] FunPtr error?

2008-06-09 Thread Judah Jacobson
2008/6/9 Galchin, Vasili [EMAIL PROTECTED]: Ryan, I tried but the compiler didn't seem to like the keyword import: [EMAIL PROTECTED]:~/FTP/Haskell/unix-2.2.0.0/tests/timer$ runhaskell Setup.lhs build Preprocessing executables for Test-1.0... Building Test-1.0... [1 of 1] Compiling

Re: [Haskell-cafe] FunPtr error?

2008-06-09 Thread Galchin, Vasili
Thanks Judah ... getting closer now. Vasili On Mon, Jun 9, 2008 at 11:25 PM, Judah Jacobson [EMAIL PROTECTED] wrote: 2008/6/9 Galchin, Vasili [EMAIL PROTECTED]: Ryan, I tried but the compiler didn't seem to like the keyword import: [EMAIL

[Haskell-cafe] FunPtr error?

2008-06-08 Thread Galchin, Vasili
Hello, I am getting what is to me a mysterious error in a test case that I am writing: [EMAIL PROTECTED]:~/FTP/Haskell/unix-2.2.0.0/tests/timer$ runhaskell Setup.lhs build Preprocessing executables for Test-1.0... Building Test-1.0... [1 of 1] Compiling Main ( ./timer.hs,

Re: [Haskell-cafe] FunPtr error?

2008-06-08 Thread Luke Palmer
2008/6/8 Galchin, Vasili [EMAIL PROTECTED]: Hello, I am getting what is to me a mysterious error in a test case that I am writing: [EMAIL PROTECTED]:~/FTP/Haskell/unix-2.2.0.0/tests/timer$ runhaskell Setup.lhs build Preprocessing executables for Test-1.0... Building Test-1.0... [1 of

Re: [Haskell-cafe] FunPtr error?

2008-06-08 Thread Galchin, Vasili
ah ..,. right ,. my bad. Vasili On Sun, Jun 8, 2008 at 10:01 PM, Luke Palmer [EMAIL PROTECTED] wrote: 2008/6/8 Galchin, Vasili [EMAIL PROTECTED]: Hello, I am getting what is to me a mysterious error in a test case that I am writing: [EMAIL

Fwd: [Haskell-cafe] FunPtr error?

2008-06-08 Thread Galchin, Vasili
So Luke .. how do I go from (Sigval - ()), i..e notifyFunc, to FunPtr using the suggested data constructors? On Sun, Jun 8, 2008 at 10:01 PM, Luke Palmer [EMAIL PROTECTED] wrote: 2008/6/8 Galchin, Vasili [EMAIL PROTECTED]: Hello, I am getting what is to me a mysterious error in a

Re: [Haskell-cafe] FunPtr error?

2008-06-08 Thread Bulat Ziganshin
Hello Vasili, Monday, June 9, 2008, 6:17:14 AM, you wrote: 1. standard place to import FunPtr from is Foreign.Ptr, not System.Posix 2. FunPtr is exported as abstract type, without constructors. you can't construct values of this type directly. instead you should use wrapper generators as in the