I'd like to better understand the following code in general.
The instances for MDouble
are included in the snippet to demonstrate an example that doesn't use the preprocessor.
#let numarray t = "\
foreign import ccall unsafe mxIs%s :: MXArrayPtr -> IO CBool\n\
instance MXArrayComponent M%s where\n\
isMXArray a = boolC =.< withMXArray a mxIs%s\n\
createMXArray s = withNDims s (uncurry $ createNumericArray (mxClassOf (undefined :: M%s)) False) >>= mkMXArray\n\
\
mxArrayGetOffset = arrayDataGet ;\
mxArraySetOffset = arrayDataSet ;\
mxArrayGetOffsetList = arrayDataGetList ;\
mxArraySetOffsetList = arrayDataSetList\
\n\
instance MXArrayData MX%s M%s\
", #t, #t, #t, #t, #t, #t
foreign import ccall unsafe mxIsDouble :: MXArrayPtr -> IO CBool
foreign import ccall unsafe mxCreateDoubleScalar :: MXDouble -> IO MXArrayPtr
foreign import ccall unsafe mxGetScalar :: MXArrayPtr -> IO MXDouble
instance MXArrayComponent MDouble where
isMXArray a = boolC =.< withMXArray a mxIsDouble
createMXScalar = mxCreateDoubleScalar . hs2mx >=> mkMXArray
mxScalarGet a = withMXArray a mxGetScalar
createMXArray s = withNDims s (uncurry $ createNumericArray (mxClassOf (undefined :: Double)) False) >>= mkMXArray
#arrayDataComponent
instance MXArrayData MXDouble MDouble
#numarray Single
#numarray Int8
#numarray Int16
#numarray Int32
#numarray Int64
#numarray Uint8
#numarray Uint16
#numarray Uint32
#numarray Uint64
But in particular, looks like they are using some types like Uint8
etc., and I'm not sure where these are defined, or why e.g. Word8
isn't used instead. Also, not sure how the %s
is being used. I see a lot of references to #
in the hsc2hs docs but so far nothing about %
.