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
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
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
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:
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
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
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
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
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
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,
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
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
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,
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
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
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
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
17 matches
Mail list logo