Re: [Haskell-cafe] FunPtr error?
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 following declarations translated to C: type Weak = Word32 {- typedef HsWord32 Weak; } Weak is just a type alias; you can use Word32 and Weak interchangeably in your code after delcaring this type. newtype Strong = Strong Word32 {- doesn't really exist in C; google for c strong typedef -} Strong behaves exactly like a Word32 at runtime, in terms of storage, but the typechecker can distinguish it from Word32. data Holder = Holder Word32 {- typedef struct { HsWord32 x; } Holder; -} Holder, on the other hand, is entirely separate from Word32; in fact, there are strictly more values in Haskell of type Holder than there are of type Word32: ha, hb, hc :: Holder -- can all be distinguished at runtime ha = undefined hb = Holder undefined hc = Holder 0 sa, sb :: Strong -- cannot be distinguished sa = undefined sb = Strong undefined ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] FunPtr error?
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 PM, Galchin, Vasili [EMAIL PROTECTED] wrote: 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 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: Unacceptable argument type in foreign declaration: Sigval When checking declaration: foreign import ccall safe wrapper mkNotify :: Notify - IO (FunPtr Notify) = here is my Sigval def data Sigval = SivalInt Int | SivalPtr (Ptr Char) I did a find/grep for Unacceptable argument in the ghc compiler source and assuming no typo I didn't find. ?? Thanks. Kind regards, 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 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:29:8: parse error on input `import' Hi Vasili, To fix that error, you probably just need to add the line Extensions: ForeignFunctionInterface to the .cabal file. (That is the equivalent of calling ghc by itself with the command-line arguments -fffi or -XForeignFunctionInterface.) Hope that helps, -Judah ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] FunPtr error?
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 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: Unacceptable argument type in foreign declaration: Sigval When checking declaration: foreign import ccall safe wrapper mkNotify :: Notify - IO (FunPtr Notify) = here is my Sigval def data Sigval = SivalInt Int | SivalPtr (Ptr Char) I did a find/grep for Unacceptable argument in the ghc compiler source and assuming no typo I didn't find. ?? Thanks. Kind regards, 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 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:29:8: parse error on input `import' Hi Vasili, To fix that error, you probably just need to add the line Extensions: ForeignFunctionInterface to the .cabal file. (That is the equivalent of calling ghc by itself with the command-line arguments -fffi or -XForeignFunctionInterface.) Hope that helps, -Judah ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] FunPtr error?
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: Unacceptable argument type in foreign declaration: Sigval When checking declaration: foreign import ccall safe wrapper mkNotify :: Notify - IO (FunPtr Notify) = here is my Sigval def data Sigval = SivalInt Int | SivalPtr (Ptr Char) I did a find/grep for Unacceptable argument in the ghc compiler source and assuming no typo I didn't find. ?? Thanks. Kind regards, 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 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:29:8: parse error on input `import' Hi Vasili, To fix that error, you probably just need to add the line Extensions: ForeignFunctionInterface to the .cabal file. (That is the equivalent of calling ghc by itself with the command-line arguments -fffi or -XForeignFunctionInterface.) Hope that helps, -Judah ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] FunPtr error?
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 PROTECTED] wrote: 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: Unacceptable argument type in foreign declaration: Sigval When checking declaration: foreign import ccall safe wrapper mkNotify :: Notify - IO (FunPtr Notify) = here is my Sigval def data Sigval = SivalInt Int | SivalPtr (Ptr Char) I did a find/grep for Unacceptable argument in the ghc compiler source and assuming no typo I didn't find. ?? Thanks. Kind regards, 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 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:29:8: parse error on input `import' Hi Vasili, To fix that error, you probably just need to add the line Extensions: ForeignFunctionInterface to the .cabal file. (That is the equivalent of calling ghc by itself with the command-line arguments -fffi or -XForeignFunctionInterface.) Hope that helps, -Judah ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] FunPtr error?
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 do something like main = do let event = Sigval { ... fill in here ... } callback - mkCallback (notify event) ... freeHaskellFunPtr callback On 6/10/08, Ryan Ingram [EMAIL PROTECTED] wrote: 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 PROTECTED] wrote: 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: Unacceptable argument type in foreign declaration: Sigval When checking declaration: foreign import ccall safe wrapper mkNotify :: Notify - IO (FunPtr Notify) = here is my Sigval def data Sigval = SivalInt Int | SivalPtr (Ptr Char) I did a find/grep for Unacceptable argument in the ghc compiler source and assuming no typo I didn't find. ?? Thanks. Kind regards, 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 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:29:8: parse error on input `import' Hi Vasili, To fix that error, you probably just need to add the line Extensions: ForeignFunctionInterface to the .cabal file. (That is the equivalent of calling ghc by itself with the command-line arguments -fffi or -XForeignFunctionInterface.) Hope that helps, -Judah ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] FunPtr error?
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 constructors. you can't construct values of this type directly. instead you should use wrapper generators as in the example that Clause has wrote. read it carefully :) 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, dist/build/timer/timer-tmp/Main.o ) ./timer.hs:11:45: Not in scope: data constructor `FunPtr' It seems like the compiler is complaining about the lack of FunPtr in it's symbol table but System.Posix is imported: module Main where import System.Posix import Foreign import Foreign.C import Foreign.Ptr main = do let event = Sigevent{sigevFunction=(FunPtr (notifyFunc))} error here timerId - timerCreate Clock_Realtime Nothing timerDelete timerId return () notifyFunc :: Sigval - IO () notifyFunc sigval = do putStrLn timer POP!!! return () I am probably looking right at the answer and not seeing it. ?? Thanks, Vasili -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] FunPtr error?
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 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 constructors. you can't construct values of this type directly. instead you should use wrapper generators as in the example that Clause has wrote. read it carefully :) 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, dist/build/timer/timer-tmp/Main.o ) ./timer.hs:11:45: Not in scope: data constructor `FunPtr' It seems like the compiler is complaining about the lack of FunPtr in it's symbol table but System.Posix is imported: module Main where import System.Posix import Foreign import Foreign.C import Foreign.Ptr main = do let event = Sigevent{sigevFunction=(FunPtr (notifyFunc))} error here timerId - timerCreate Clock_Realtime Nothing timerDelete timerId return () notifyFunc :: Sigval - IO () notifyFunc sigval = do putStrLn timer POP!!! return () I am probably looking right at the answer and not seeing it. ?? Thanks, Vasili -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] FunPtr error?
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 6/9/08, Galchin, Vasili [EMAIL PROTECTED] wrote: 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 This will be suitable for that purpose. -- ryan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] FunPtr error?
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, dist/build/timer/timer-tmp/Main.o ) ./timer.hs:29:8: parse error on input `import' source ...: module Main where import System.Posix import Foreign import Foreign.C import Foreign.Ptr type Notify = Sigval - IO () main = do notifyFPtr - mkNotify notifyFunc let event = Sigevent{sigevFunction=notifyFPtr} timerId - timerCreate Clock_Realtime Nothing timerDelete timerId return () notifyFunc :: Sigval - IO () notifyFunc sigval = do putStrLn timer POP!!! return () foreign import ccall wrapper mkNotify :: Notify - IO (FunPtr Notify) ~ Everything looks ok to me. ?? Regards, Vasili On Mon, Jun 9, 2008 at 2:16 PM, Ryan Ingram [EMAIL PROTECTED] wrote: 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 6/9/08, Galchin, Vasili [EMAIL PROTECTED] wrote: 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 This will be suitable for that purpose. -- ryan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] FunPtr error?
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 Main ( ./timer.hs, dist/build/timer/timer-tmp/Main.o ) ./timer.hs:29:8: parse error on input `import' Hi Vasili, To fix that error, you probably just need to add the line Extensions: ForeignFunctionInterface to the .cabal file. (That is the equivalent of calling ghc by itself with the command-line arguments -fffi or -XForeignFunctionInterface.) Hope that helps, -Judah ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] FunPtr error?
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 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:29:8: parse error on input `import' Hi Vasili, To fix that error, you probably just need to add the line Extensions: ForeignFunctionInterface to the .cabal file. (That is the equivalent of calling ghc by itself with the command-line arguments -fffi or -XForeignFunctionInterface.) Hope that helps, -Judah ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] FunPtr error?
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 1] Compiling Main ( ./timer.hs, dist/build/timer/timer-tmp/Main.o ) ./timer.hs:11:45: Not in scope: data constructor `FunPtr' There is a *type* called FunPtr in scope, but not a data constructor as you are using it. That is, you could say: foo :: FunPtr (Int - IO ()) That is, use the type called FunPtr, but you may not use a *function* called FunPtr, because it doesn't exist. You need to use functions like nullFunPtr, castPtrToFunPtr, etc. to construct FunPtrs. Luke ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] FunPtr error?
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 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:11:45: Not in scope: data constructor `FunPtr' There is a *type* called FunPtr in scope, but not a data constructor as you are using it. That is, you could say: foo :: FunPtr (Int - IO ()) That is, use the type called FunPtr, but you may not use a *function* called FunPtr, because it doesn't exist. You need to use functions like nullFunPtr, castPtrToFunPtr, etc. to construct FunPtrs. Luke ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] FunPtr error?
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 example that Clause has wrote. read it carefully :) 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, dist/build/timer/timer-tmp/Main.o ) ./timer.hs:11:45: Not in scope: data constructor `FunPtr' It seems like the compiler is complaining about the lack of FunPtr in it's symbol table but System.Posix is imported: module Main where import System.Posix import Foreign import Foreign.C import Foreign.Ptr main = do let event = Sigevent{sigevFunction=(FunPtr (notifyFunc))} error here timerId - timerCreate Clock_Realtime Nothing timerDelete timerId return () notifyFunc :: Sigval - IO () notifyFunc sigval = do putStrLn timer POP!!! return () I am probably looking right at the answer and not seeing it. ?? Thanks, Vasili -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe