我试图理解c2hs
和gtk2hsC2hs
(c2hs
用于的修改版本gtk2hs
)之间的区别。考虑以下编码:
module Matrix where
data Matrix = Matrix { xx :: !Double, yx :: !Double,
xy :: !Double, yy :: !Double,
x0 :: !Double, y0 :: !Double }
deriving (Show, Eq)
{#pointer *cairo_matrix_t as MatrixPtr -> Matrix#}
instance Storable Matrix where
sizeOf _ = {#sizeof cairo_matrix_t#}
alignment _ = alignment (undefined :: CDouble)
peek p = do
xx <- {#get cairo_matrix_t->xx#} p
yx <- {#get cairo_matrix_t->yx#} p
xy <- {#get cairo_matrix_t->xy#} p
yy <- {#get cairo_matrix_t->yy#} p
x0 <- {#get cairo_matrix_t->x0#} p
y0 <- {#get cairo_matrix_t->y0#} p
return $ Matrix (realToFrac xx) (realToFrac yx)
(realToFrac xy) (realToFrac yy)
(realToFrac x0) (realToFrac y0)
poke p (Matrix xx yx xy yy x0 y0) = do
{#set cairo_matrix_t->xx#} p (realToFrac xx)
{#set cairo_matrix_t->yx#} p (realToFrac yx)
{#set cairo_matrix_t->xy#} p (realToFrac xy)
{#set cairo_matrix_t->yy#} p (realToFrac yy)
{#set cairo_matrix_t->x0#} p (realToFrac x0)
{#set cairo_matrix_t->y0#} p (realToFrac y0)
return ()
{#context lib="cairo" #}
{#fun cairo_pattern_set_matrix as patternSetMatrix { unPattern `Pattern', `Matrix'} -> `()'#}
{#fun cairo_pattern_get_matrix as patternGetMatrix { unPattern `Pattern', alloca- `Matrix' peek*} -> `()'#}
第二fun
行(例如cairo_pattern_get_matrix
)适用于两种工具(尽管生成的代码不同),而第一行(例如cairo_pattern_set_matrix
)仅适用于gtk2hsC2hs
.
使用时的错误信息c2hs
是:
Test.chs:35: (column 75) [ERROR] >>> Missing "in" marshaller!
There is no default marshaller for this combination of Haskell and C type:
Haskell type: Matrix
C type : (MatrixPtr)
我不清楚这里的问题,但从我的角度来看,这应该是有效的。
我用于c2hs
:
C->Haskell Compiler, version 0.28.3 Switcheroo, 25 November 2017
build platform is "x86_64-linux" <1, True, True, 1>
和gtk2hsC2hs
:
C->Haskell Compiler, version 0.13.13 (gtk2hs branch) "Bin IO", 27 May 2012
提前致谢