0

In the following code, it looks like numarray only takes one parameter, so I'm not sure what the repeated #t is used for, but it causes an abnormal exit of hsc2hs when not all are present:

#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
bbarker
  • 11,636
  • 9
  • 38
  • 62
  • 1
    I guess each `%s` in the long code-carrying string is replaced with its own argument, so we need to pass the string `#t` many times? I'm not too familiar with hsc2hs. – chi Jun 11 '20 at 20:40
  • @chi, that was my guess too, but I removed the first `foreign` line that is part of the `#let` definition, and it seemed like it still needed 6 of the `#t` ... but wait, I now realize, after discovering I had another error that partially masked this one with hsc2hs, that you are correct. If I'd run `stack clean` before each `stack build` I'd have found this earlier, but hsc2hs will leave behind partially generated hs files that may allow the overall build to complete. – bbarker Jun 11 '20 at 21:07
  • If you have found an answer to your question you should either write it below (if you think it can be helpful to others), or delete the question (if you think it was only a minor build issue). – chi Jun 12 '20 at 07:44

1 Answers1

0

As @chi pointed out in a comment, each %s is replaced by an argument (much like in printf and friends). I guessed this initially, but when testing this, the result was hidden by some silent errors in my usage of hsc2hs (see comment for details).

bbarker
  • 11,636
  • 9
  • 38
  • 62