I'm trying to build a wrapper for a C library. and it has some strange syntax with question marks that I've never seen before:
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
It's causing a syntax error when I compile:
src/System/FlyCap.hs:185:21: parse error on input ‘?’
Looking up "?" on Hoogle finds something about 'implicit parameters' but that doesn't seem to be related. I tried replacing the mysterious question marks with type holes:
return CImage (_ _ _ pixelVals' _ _ _ _)
That gave me a much bigger error:
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);
.... }
I'm really not sure of how to proceed. Any tips?
UPDATE: I found the original repo, which seems to have fixed this, but I still wonder what the question marks are?
The ?
is not a syntax, its a valid operator in haskell. But here its just a "some magic here" thing.
The authors, as marked above, just forgot to replace it with some expression involving the pixelVals'
. Most probably, it should be the construction of CImage
parameter(s?) out of that pixel values.
Ghc's parser will give parse error
on any two sequental tokens made of operator symbols (except for -
) - because of that it failed after the second question mark.