data Color = Color !Word8 !Word8 !Word8 !Word8 deriving (Show, Eq)
instance Storable Color where
...
#include "foo.h"
{# fun unsafe ClearBackground as ^ {with* %`Color'} -> `()' #}
During the build Lib.chs.c is generated by C2HS and contains:
src/Lib.chs:26:21: error:
• Couldn't match type ‘Color’ with ‘()’
Expected type: C2HSImp.Ptr ()
Actual type: C2HSImp.Ptr Color
• In the first argument of ‘clearBackground'_’, namely ‘a1'’
In the first argument of ‘(>>)’, namely ‘clearBackground'_ a1'’
In the expression: clearBackground'_ a1' >> return ()
The problem is that the generated C wrapper accepts a Color * (a Color pointer), but the "foreign import" tells Haskell that it accepts a Ptr (). It should be Ptr Color instead of Ptr () I believe, something like:
I have the following code in
Lib.chs
:During the build
Lib.chs.c
is generated by C2HS and contains:And
Lib.hs
is also generated by C2HS and contains, in part:Which results in the following type error:
The problem is that the generated C wrapper accepts a
Color *
(a Color pointer), but the "foreign import" tells Haskell that it accepts aPtr ()
. It should bePtr Color
instead ofPtr ()
I believe, something like:A full (yet minimal) demo can be checked out from a repo I created: https://github.com/DevJac/c2hs-bug-demo
C2HS version:
I'm using Cabal 3.0 and GHC 8.6.5.