ghcjs / ghcjs-base

base library for GHCJS for JavaScript interaction and marshalling, used by higher level libraries like JSC
MIT License
45 stars 67 forks source link

Cannot set TypedArrayData in XMLHttpRequest.RequestData #58

Open ElvishJerricco opened 8 years ago

ElvishJerricco commented 8 years ago

This code:

import           JavaScript.TypedArray
import qualified JavaScript.Web.XMLHttpRequest as XHR

setData :: Uint8Array -> XHR.Request -> XHR.Request
setData u8 req = req { XHR.reqData = XHR.TypedArrayData u8 }

Produces this error message:

Couldn't match kind ‘AnyK’ with ‘*’
Expected type: ghcjs-base-0.2.0.0:JavaScript.TypedArray.Internal.Types.SomeTypedArray
                 e 'ghcjs-base-0.2.0.0:GHCJS.Internal.Types.Immutable
  Actual type: Uint8Array
In the first argument of ‘XHR.TypedArrayData’, namely ‘u8’
In the ‘XHR.reqData’ field of a record

As far as I can tell, this is the intended purpose of XHR.TypedArrayData, so I'm not sure why it doesn't work.

iand675 commented 8 years ago

I'm seeing the same issue. @mgsloan any ideas?

mgsloan commented 8 years ago

Hmm, I'm not sure what's going wrong there. One possible hack would be to coerce u8, should be representationally equivalent.

iand675 commented 8 years ago

Yeah, I ended up slapping an unsafeCoerce on to get around it shortly after commenting on the issue, but there's definitely a bit of an impedance mismatch at the type level that appears to make XHR.TypedArrayData not usable without coercion.

mikelpr commented 5 years ago

got bit by this today