1

I've got a ByteString that I need to send over XHR in GHCJS, but I can't for the life of me figure out how to get that ByteString into XHR's RequestData

data RequestData = NoData
                 | StringData     JSString
                 | TypedArrayData (forall e. SomeTypedArray e Immutable)
                 | FormData       [(JSString, FormDataVal)]

Obviously TypedArrayData is what I need to use, but I'm having no luck at all figuring out how to convert a ByteString to fit in there. I looked at this, and I tried something like this.

setData r bs = do
    let (b, _, _) = fromByteString $ toStrict bs
    return r { XHR.reqData = XHR.TypedArrayData $ getUint8Array b }

But for some reason, I'm getting a weird error with the kinds.

Couldn't match kind ‘AnyK’ with ‘*’
Expected type: GHCJS.Buffer.Types.SomeBuffer
                 'ghcjs-base-0.2.0.0:GHCJS.Internal.Types.Immutable
  Actual type: Buffer
In the first argument of ‘getUint8Array’, namely ‘b’
In the second argument of ‘($)’, namely ‘getUint8Array b’

As far as I can tell, there's no reason these types should be incompatible.

Will Fancher
  • 245
  • 3
  • 10

0 Answers0