Add base types of ArrayBuffer, SharedArrayBuffer#6683
Add base types of ArrayBuffer, SharedArrayBuffer#6683cometkim wants to merge 3 commits intorescript-lang:11.0_releasefrom
Conversation
6b88b9f to
6e73d3a
Compare
|
This should be moved into Core. Onlt |
ce2c6b9 to
7f64c21
Compare
| @@ -0,0 +1,6 @@ | |||
| type t = { | |||
There was a problem hiding this comment.
I'd suggest marking the record as private so it's not possible to create by hand.
There was a problem hiding this comment.
Since not every record with the fields is the ArrayBuffer
There was a problem hiding this comment.
That's basically prevented by nominal typing
There was a problem hiding this comment.
I mean to prevent the code like this:
let myArrayBuffer: Js.ArrayBuffer.t = {
byteLenght: 2,
maxByteLength: 4,
detached: false,
resizable: false
}
There was a problem hiding this comment.
If we don't want that, we shouldn't use the binding pattern of exposing getters as record fields for every this-bounded object.
I thought it was already a widely used (even encouraged) pattern, more for practicality than strictness. for example: TheSpyder/rescript-webapi#78 (comment)
There was a problem hiding this comment.
I personally use private for my projects. It kind of solves the problem:
type t = private {
byteLength: int,
maxByteLength: int,
detached: bool,
resizable: bool,
}
But I see one downside compared to getter pattern:
You need to annotate the value when you access the field
let fn = (arrayBuffer: ArrayBuffer.t) => arrayBuffer.byteLenght
// vs
let fn = (arrayBuffer) => arrayBuffer->Js.ArrayBuffer.byteLength
It's fine for this case but when you have a type with a lot of complicated type arguments I prefer not to write annotations.
There was a problem hiding this comment.
Maybe we can just leave type t here, but what about the Core's direction? @zth
I'll tune in to that.
There was a problem hiding this comment.
Wait, so does it make sense to provide compatibility with Js' type in the first place?
|
ok I'm going to close this and move it to Core entirely. If the direction is to remove JS in v12, I think there is no reason to change here, regardless of whether |
TypedArray.prototype.bufferis polymorphic.ArrayBufferorSharedArrayBufferAtomicsis mostly used withInt32Arrayon SAB.It's quite a corner case, but not a common use case, so I think it's not practical to make the module structure or type variants represent it strictly.