Skip to content

Object.is documentation - #100

Closed
jmagaram wants to merge 10 commits into
rescript-lang:mainfrom
jmagaram:Object.is
Closed

jmagaram wants to merge 10 commits into
rescript-lang:mainfrom
jmagaram:Object.is

Conversation

@jmagaram

Copy link
Copy Markdown
Contributor

Documentation for Object.is. Also some tests mostly so I could verify how it all works. Took the liberty of documenting some of == and === at the same time. Read through the Mozilla docs and tried to summarize.

@jmagaram

Copy link
Copy Markdown
Contributor Author

According to Mozilla docs "In general, the only time Object.is special behavior towards zeros is likely to be of interest is in the pursuit of certain meta-programming schemes...suggested to avoid".

@zth

zth commented Mar 15, 2023

Copy link
Copy Markdown
Member

This is looking great! Out traveling, but will try to review properly as soon as I can.

Comment thread src/Core__Object.res Outdated
Comment on lines +8 to +10
The `==` operator [is different in ReScript than Javascript](https://rescript-lang.org/docs/manual/latest/overview#boolean). Arrays, records and other non-primitives are equal if they have the same contents (deep equality).

In ReScript, the `===` operator performs a strict equality check, like Javascript, and is similar but not identical to `is`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Describing other functions and operators seem outside the scope of reference documentation. It will quickly become hard to maintain the documentation if it gets scattered across other definitions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thanks for the feedback.

Comment thread src/Core__Object.res Outdated
```
*/
@val
external is: ('a, 'b) => bool = "Object.is"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this type signature makes sense. By definition you'd think that objects of different types wouldn't be considered identical, and you might as well weed that out at compile time.

There are of course exceptions, such as JSON-encoded primitives, but better to require explicitness than cater to convenience for weird edge cases I think.

I would therefore suggest this instead:

Suggested change
external is: ('a, 'b) => bool = "Object.is"
external is: ('a, 'a) => bool = "Object.is"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I'll change it.

@jmagaram

Copy link
Copy Markdown
Contributor Author

Git problems here. I broke the tests because I uploaded the type signature change but forgot to remove tests that compare different types. I don't know how to fix it. Sorry! Do I do a git pull rebase? VS Code wants me to do a Sync but it isn't working. Not sure what steps to do in VS Code. Don't want to lose work here. Or you can fix it if it is easy for you.

@jmagaram

Copy link
Copy Markdown
Contributor Author

Ok fixed it.

@jmagaram

Copy link
Copy Markdown
Contributor Author

Consolidated into #117

@jmagaram jmagaram closed this Jul 12, 2023
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