Skip to content

Conversation

htoooth
Copy link

@htoooth htoooth commented Sep 12, 2025

No description provided.

@zth zth requested review from cknitt and cometkim September 12, 2025 12:46
Copy link

pkg-pr-new bot commented Sep 12, 2025

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@7881

@rescript/darwin-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-arm64@7881

@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@7881

@rescript/linux-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-arm64@7881

@rescript/linux-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-x64@7881

@rescript/runtime

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/runtime@7881

@rescript/win32-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/win32-x64@7881

commit: f9c494b

@cknitt
Copy link
Member

cknitt commented Sep 12, 2025

@htoooth Thank you for your contribution! 👍

Instead of two bindings per function like

@send external getInt16: (t, int) => int = "getInt16"
@send external getInt16LittleEndian: (t, int, @as(1) _) => int = "getInt16"

could you do single bindings like

@send external getInt16: (t, int, ~littleEndian: bool=?) => int = "getInt16"

please?

(Bonus points for adding doc strings with tests/code examples 🙂.)

@htoooth
Copy link
Author

htoooth commented Sep 12, 2025

@cknitt

  1. I did it this way because I saw that's how it was done in the previous v11.
  2. The idea of encapsulating polymorphic functions mentioned in the document is also to encapsulate for different situations.
  3. This makes it easier to migrate old code.

By the way, I also initially thought of adding a parameter like your said @cknitt

Where to add tests and documentation? I couldn't find the previous documents and test cases

@cometkim
Copy link
Member

Using @as(1) _ here is neat btw

@cknitt
Copy link
Member

cknitt commented Sep 12, 2025

I did it this way because I saw that's how it was done in the previous v11.

In previous ReScript versions, the approach with the optional argument was not really ergonomic because a trailing unit argument was required.

Now that it has become feasible, we have moved to single bindings in the stdlib where possible, as this is much clearer to JS devs, basically resulting in a 1:1 correspondence with the JS APIs as documented on MDN.

E.g. Float.toString with optional parameter radix, deprecating Float.toStringWithRadix. There are many more such examples in the new stdlib.

Therefore, also the DataView bindings should follow suit.

Docstrings are in a corresponding .resi file and contain examples that are automatically verified as test assertions during the CI build.

Example:

`toString(v)` return a `string` representing the given value.

@htoooth
Copy link
Author

htoooth commented Sep 13, 2025

@cknitt I have made the revisions and added the doc.

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

Successfully merging this pull request may close these issues.

3 participants