-
Notifications
You must be signed in to change notification settings - Fork 455
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
Add BigInt bindings #5350
Add BigInt bindings #5350
Conversation
|
||
external ofString : string -> t = "BigInt" [@@bs.val] | ||
external ofInt : int -> t = "BigInt" [@@bs.val] | ||
external ofFloat : float -> t = "BigInt" [@@bs.val] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is dangerous enough that I think we may not want to include it.
The ReScript expression ofFloat(99999999999999999999999999999.)
for example will produce the value 99999999999999991433150857216n
as the float literal will be truncated by the JS environment.
Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What OCaml version is being used to compile ReScript nowadays? Newer OCaml versions have an 'alert' feature that trigger a warning if you use some piece of code. E.g. I'm doing that in https://github.com/yawaramin/ocaml-decimal/blob/08c57183c8673b5058bd6010570e69f0201c03c7/lib/decimal.mli#L321
If that's not available, perhaps we can mark this function as deprecated with the @deprecated
tag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alert
doesn't seem to be available: https://github.com/rescript-lang/rescript-compiler/blob/master/jscomp/ml/builtin_attributes.mli
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall, we will also need the comparison and equality operators.
|
||
external ofString : string -> t = "BigInt" [@@bs.val] | ||
external ofInt : int -> t = "BigInt" [@@bs.val] | ||
external ofFloat : float -> t = "BigInt" [@@bs.val] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What OCaml version is being used to compile ReScript nowadays? Newer OCaml versions have an 'alert' feature that trigger a warning if you use some piece of code. E.g. I'm doing that in https://github.com/yawaramin/ocaml-decimal/blob/08c57183c8673b5058bd6010570e69f0201c03c7/lib/decimal.mli#L321
If that's not available, perhaps we can mark this function as deprecated with the @deprecated
tag.
ts2ocaml would greatly benefit from having I'm willing to help this if you need a hand. |
How about reviving this? |
I've created a PR in which added the BigInt module #5531. I think it should be good enough as the first iteration. |
I am thinking we may provide native bigint in the long term |
What's required specifically for |
#5539 solved the core problem, as ts2ocaml now don't have to define bigint on our own and just use It would certainly help if we can have a proper bigint binding, but it doesn't need to be available as soon as possible 🙂 |
Going to close this PR now that we have #5539. I wanted to add these so that we can have a shared |
Relates to #4677.
This is my first ever ocaml code, would appreciate if someone could help getting the PR ready to be merged - or just outline what I need to do. Thanks!