Skip to content

Make ArrayBuffer creation effectful #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

sgronblo
Copy link

  • Remove the Writer effect from Typed.purs
  • Move down the WRITER and READER effects from DataView to ArrayBuffer
  • Simplify by combining WRITER and READER into a single ARRAYBUFFER
    effect
  • Updated tests to deal with the Eff values

Initial attempt. Maybe some things that could be pure are effectful and vice versa.

- Remove the Writer effect from Typed.purs
- Move down the WRITER and READER effects from DataView to ArrayBuffer
- Simplify by combining WRITER and READER into a single ARRAYBUFFER
effect
- Updated tests to deal with the Eff values
@jacereda
Copy link
Collaborator

Looks good, I'll merge later my effectful branch to see if it contains any useful bit.
I haven't seen a compound name effect before, so I'm not sure what the convention would be for:

arraybuffer :: ARRAYBUFFER

vs

arrayBuffer :: ARRAYBUFFER

@jacereda jacereda merged commit 9bcd95d into purescript-contrib:master Jan 17, 2017
@jacereda
Copy link
Collaborator

Merged, thanks!

@jacereda
Copy link
Collaborator

In my branch asInt8Array and friends are effectful, any reason to keep them pure?

@sgronblo
Copy link
Author

@jacereda I was trying to ask around about this in #purescript last night. I extracted the relevant conversation with natefaubion here:

22:19 < sgronblo> hmm, what do you think should a conversion like foreign import asInt8Array :: DataView -> Int8Array be pure or impure?
22:25 < natefaubion> sgronblo: if Int8Array is immutable then you should be able to make that pure
22:25 < natefaubion> if Int8Array is a mutable reference, then it needs to be effectful
22:52 < sgronblo> natefaubion: well i think the int8array is kind of a mutable view onto an arraybuffer
22:54 < natefaubion> sgronblo: how would you implement the function?
22:56 < sgronblo> this is whats in the library   return new Int8Array(v.buffer, v.byteOffset, v.byteLength);
22:56 < sgronblo> so it feels like it could be pure to me
22:57 < sgronblo> we are not modifying the underlying buffer
22:57 < natefaubion> sgronblo: if it is copying data from v.buffer, based on the offset and length, then it is pure.
22:58 < natefaubion> but if it is only maintaining a pointer to v.buffer, and v.buffer’s contents can change, then it is not pure
23:00 < sgronblo> arent we only like repackaging a mutable value that has already been created?
23:00 < sgronblo> like putting an ioref into a tuple?
23:01 < natefaubion> It’s hard for me to say because I don’t know the details of the API you are wrapping
23:02 < sgronblo> https://github.com/jacereda/purescript-arraybuffer which is wrapping https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer
23:03 < sgronblo> you first create an arraybuffer, but you cant manipulate it directly
23:03 < sgronblo> you have to wrap it in either a dataview or a typed array
23:03 < sgronblo> this operation concerns the conversion from dataview to typed array
23:04 < sgronblo> so i was under the impression that creating arraybuffers and modifying them through either of the wrapping structures are definitely impure. but this wrapping in itself seems like it could be considered pure to me.
23:06 < natefaubion> sgronblo: once you get the int8array from the DataView, will updates to the DataView be reflected in the int8array you got out of it?
23:06 < natefaubion> subsequent updates I should say
23:07 < natefaubion> like, is the assumption that int8array is immutable?
23:07 < natefaubion> or is the int8array mutable as well?
23:08 < natefaubion> if it’s the case that its mutable as well, I’d say its only pure if any operations on it are effectful, in which case its basically a coercion, but I don’t know the depths of the API so its hard for me to say
23:09 < sgronblo> i also dont have very much experience working with arraybuffers
23:09 < natefaubion> like a Tuple around Refs, the Tuple is pure, but I can’t get any data out of the refs except through effects
23:09 < afcondon> like, for starters, where are those defintions of `ap` and `return` actually coming from in the definition of Applicative instance?
23:09 < sgronblo> but i am not sure you can say that int8array is mutable or not. it is wrapping the underlying arraybuffer which is mutable.
23:10 < sgronblo> natefaubion: right, but wrapping the refs in a tuple should be pure?
23:10 < natefaubion> sgronblo: if you can only read the int8array effectfully, then it is pure
23:10 < natefaubion> like you can still only read the refs in the tuple effectfully
23:10 < natefaubion> does that make sense?
23:10 < natefaubion> the wrapper is pure in the tuple, but the contents are still effectful
23:11 < sgronblo> yeah any operations through the int8array would of course be effectful
23:12 < natefaubion> then its probably fine
23:12 < sgronblo> thanks for your input

@jacereda
Copy link
Collaborator

If that's true, I guess the old API was good. Things like slice could be pure as long as the getters/setters are effectful. Am I wrong?

@sgronblo
Copy link
Author

Possibly. I wasn't really sure if I was going overboard with changing too much to be effectful.

@jacereda
Copy link
Collaborator

Just pushed a new version, if you feel it's ok I'll tag and update purescript-binary accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants