
On Sat, 2005-11-26 at 00:55 -0500, Cale Gibbard wrote:
Hello, I've just started writing bindings to the Enlightenment Foundation Libraries, using c2hs. I've run into the following problem with the types in the foreign import declarations generated.
In Imlib2.h, there is a function prototype: int imlib_get_visual_depth(Display * display, Visual * visual);
In Imlib.chs, I have (among other things) import qualified Graphics.X11.Xlib.Types as Xlib -- ... {# fun imlib_get_visual_depth as getVisualDepth { id `Xlib.Display', id `Xlib.Visual' } -> `Int' #}
I run: c2hs -k /usr/local/include/Imlib2.h Imlib.chs
and in the resulting Imlib.hs, I get:
--- this part is correct: getVisualDepth :: Xlib.Display -> Xlib.Visual -> IO (Int) getVisualDepth a1 a2 = let {a1' = id a1} in let {a2' = id a2} in getVisualDepth'_ a1' a2' >>= \res -> let {res' = cIntConv res} in return (res')
--- this part is not: foreign import ccall safe "Imlib.h imlib_get_visual_depth" getVisualDepth'_ :: ((Ptr ()) -> ((Ptr ()) -> (IO CInt)))
Why did it choose the type Ptr (), when I gave the type Xlib.Display?
You need to tell c2hs about the relationship between C types and Haskell types. http://www.cse.unsw.edu.au/~chak/haskell/c2hs/docu/c2hs-3.html#ss3.10 You'll want to add something like: {# pointer *Display -> Display #} {# pointer *Visual -> Visual #} Note that c2hs doesn't yet accept qualified names like: {# pointer *Display -> Xlib.Display #} Duncan