我正在尝试为 C 库构建一个包装器。它有一些我以前从未见过的带有问号的奇怪语法:
cvLoadImage :: Capture -> IO CImage
cvLoadImage capture = do
(Just imageRGB) <- getFrame capture
let imageD32 = rgbToGray imageRGB
let (CArray (nx0, ny0) (nx1, ny1) numElem values) = copyImageToFCArray imageD32
pixelVals <- (withForeignPtr values) (peekArray numElem)
let pixelVals' = map (fromIntegral . truncate . (*255)) pixelVals
ptr <-( mallocArray (numElem) ::IO (Ptr Word8))
pokeArray ptr pixelVals'
return CImage (? ? ? pixelVals' ? ? ? ?) -- this is the line I'm confounded by
编译时会导致语法错误:
src/System/FlyCap.hs:185:21: parse error on input ‘?’
抬头看“?” 在 Hoogle 上发现了一些关于“隐式参数”的东西,但这似乎并不相关。我尝试用类型孔替换神秘的问号:
return CImage (_ _ _ pixelVals' _ _ _ _)
这给了我一个更大的错误:
src/System/FlyCap.hs:186:4:
Couldn't match type ‘IO CImage’
with ‘CUInt
-> CUInt
-> CUInt
-> Ptr CUChar
-> CUInt
-> CInt
-> CInt
-> Ptr ()
-> CImage’
Expected type: t6 -> IO CImage
Actual type: t6
-> CUInt
-> CUInt
-> CUInt
-> Ptr CUChar
-> CUInt
-> CInt
-> CInt
-> Ptr ()
-> CImage
The function ‘return’ is applied to two arguments,
but its type ‘(CUInt
-> CUInt
-> CUInt
-> Ptr CUChar
-> CUInt
-> CInt
-> CInt
-> Ptr ()
-> CImage)
-> t6
-> CUInt
-> CUInt
-> CUInt
-> Ptr CUChar
-> CUInt
-> CInt
-> CInt
-> Ptr ()
-> CImage’
has only 10
In a stmt of a 'do' block: return CImage (_ _ _ pixelVals' _ _ _ _)
In the expression:
do { (Just imageRGB) <- getFrame capture;
let imageD32 = rgbToGray imageRGB;
let (CArray (nx0, ny0) (nx1, ny1) numElem values)
= copyImageToFCArray imageD32;
pixelVals <- (withForeignPtr values) (peekArray numElem);
.... }
我真的不确定如何进行。有小费吗?
更新:我找到了原始仓库,它似乎已经解决了这个问题,但我仍然想知道问号是什么?