[Haskell-cafe] c2hs confusion with a simple function

Jeff Heard jefferson.r.heard at gmail.com
Thu Jul 9 16:45:46 EDT 2009

The c2hs documentation at
 gives me an example to follow for this case:

{#fun notebook_query_tab_label_packing as ^
  `(NotebookClass nb, WidgetClass cld)' =>
  {notebook `nb'                ,
   widget   `cld'               ,
   alloca-  `Bool'     peekBool*,
   alloca-  `Bool'     peekBool*,
   alloca-  `PackType' peekEnum*} -> `()'#}

so I took the original C binding:

   void SHPGetInfo(SHPHandle, int*, int*, double*, double*)

And wrote a c2hs binding:

{#fun SHPGetInfo as getInfo
    { fromSHPHandle `SHPHandle'
    , alloca- `Int'
    , alloca- `Int'
    , alloca- `Double'
    , alloca- `Double'
    } -> `()' #}

The error I get:

    Couldn't match expected type `Int'
           against inferred type `(Ptr b -> IO c) -> IO c'
      Expected type: IO (Int, Int, Double, Double)
      Inferred type: IO
                       ((Ptr b -> IO c) -> IO c,
                        (Ptr b1 -> IO c1) -> IO c1,
                        (Ptr b2 -> IO c2) -> IO c2,
                        (Ptr b3 -> IO c3) -> IO c3)
    In the expression:
          alloca $ \ a2' -> alloca $ \ a3' -> alloca $ \ a4' -> ...
    In the expression:
        let a1' = fromSHPHandle a1
        in alloca $ \ a2' -> alloca $ \ a3' -> alloca $ ...

I've tried ending it with withCIntConv and withCFloatConv to no avail.
 The original c2hs file is attached.  I'm sure there are many more
problems, but this is the one I'm working on at the moemnt...

-- Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Internal.chs
Type: application/octet-stream
Size: 3634 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090709/3b467892/Internal-0001.obj

More information about the Haskell-Cafe mailing list