yulia
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # R&T / Deep Equality discussion Three contrasting implementations - objects without identity - R&T as primitives - A new integrity level, a new equality operation (not used by existing maps and sets) - A new deep eq. operator ### Question 1: Does a deep equality operator make Records and Tuples better in terms of implementation? Problem 1: if R&T are objects, what happesn to builtin methods? ```javascript! x = [#{a}]; x.includes(#{a}) // if this is an object, it will be false x.includes(#{a}) // if this is a primitive, it will be true ``` `a ~ b, where a = {}, b = {}, will be true` proposal: Change the semantics, to check for immutability Proposal 2: Special casing builtin methods to treat records and tuples specially, feels wrong. We should instead introduce new methods that check deep equality, as they are functionally different. ```javascript! x = [#{a}]; x.includes_deep(#{a}) // if this is an object, it will be true ``` proposal 3: ```javascript! x = [#{a}]; x.includes(#{a}, (a, b) => a ~ b) // if this is an object, it will be true y = [{a}]; y.includes({a}, (a, b) => a ~ b) // if this is an object, it will be true ``` Counter idea: If records and tuples are primitives, then one way we can implement deep equality is by casting to a record or a tuple for various complex types. This is equivalent to ```javascript! x = { [Symbol[@@ToPrimitive]] () { return Record.toRecord(this); } } x === #{} // false, an argument for deep equality operator. x =~= #{} // true Object.deepEqual(x, y) // an alternative syntax ``` ```javascript! Object.deepEqual = function deepEqual(x, y) { return x[@@ToPrimitive](x) == y[@@ToPrimitive](y); } ``` # Idea: Introduce interned objects Atomized objects are extractions of the observable surface area of an object. They are not _equal_ to their source object, they are an _immutable representation of their detectable surface area_. In this case - The R&T syntax becomes a sugar for atomized objects. ## A shim: ```javascript! // hidden object var hashed = {} // Note: this is not complete, obviously. We would have // a different algorithm to do this. This is a short // hand. let PLACEHOLDER_SERIALIZER = JSON.parse; let PLACEHOLDER_IDENTITY_EXTRACTOR = JSON.stringify; // the api function intern(object) { if (object !== Object(object)) { return object; } let identity = PLACEHOLDER_IDENTITY_EXTRACTOR(object); if (hashed[identity]) { return hashed[identity]; } let newObj = Object.create(null) let jsonObj = PLACEHOLDER_SERIALIZER(identity); let props = Object.getOwnPropertyNames(jsonObj); for (let property of props) { newObj[property] = jsonObj[property]; } // Note: in this case, objects are frozen for their // identity to work. However, an alternative is possible. // If the object is modified, it's identity is // different, and it will be a copy. // Immutability is not required for this // to work, but it makes this easier. Object.freeze(newObj); hashed[identity] = newObj; return hashed[identity]; // Note, also not implemented here: we don't do // memoization, but this would be a core part of what is // built in here. } ``` Example with proxies: ```javascript! const target = { message1: "hello", message2: "everyone" }; const handler1 = {}; const proxy1 = new Proxy(target, handler1); atomize(target) === atomize(proxy1); // true ``` What we introduce is not immutability, but object identities tied to structure. https://github.com/PapenfussLab/bionix ### Question 2: Does having a deep equality operator make other things in the language better? - Deep equality is interesting when you are comparing many things, many times. if this is the case, then you can do the atomization technique. - With the toPrimative, it is difficult to tell apart the difference that you would have if the records and tuples proposal went ahead as a primitive. rough syntax ```javascript! a ~ b a ~= b a ==== b //etc. ``` Notes: - Functions in general do not satisfy deep equality - therefore getters do not either. Or any function on an objects as an ownProperty. - This will, as a consequence, disallow proxies. - Deep equality should not have the side effect of creating properties as it is checking. The shim so far ```javascript! function externalEq(a, b) { return someEquality(a, b); } function someEquality(a, b, past = []) { if (past.includes(a)) { if (a === b) { return true; } return false } console.log("comparing ", a, b); if (a !== Object(a)) { if (a === b) { return true } return false } if (a[Symbol["StructEq"]] === b[Symbol["StructEq"]]) { if (a[Symbol["StructEq"]]) { // Callable? return a[Symbol["StructEq"]](b); } } else { return false; } if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) { return false; } if (typeof a === "function") { return a === b; } let aProps = Object.getOwnPropertyNames(a); if (aProps.length != Object.getOwnPropertyNames(b).length) { return false; } for (const property of aProps) { if (property === "prototype") { continue; } if (!Object.hasOwn(b, property)) { console.log('different hasown ', b, property) return false } let testedPropA = a[property]; let testedPropB = b[property]; if (testedPropA !== Object(testedPropA)) { if (testedPropA !== testedPropB) { console.log('different prop value: ', testedPropA, testedPropB) return false; } } if (testedPropA === a && testedPropB === b && a === b) { continue; } console.log("object test, ", property); if (property === "constructor") { if (testedPropA !== testedPropB) { return false; } continue; } past.push(a); if (!someEquality(testedPropA, testedPropB, past)) { console.log('structural equality failure: ', testedPropA, testedPropB) return false; } } return true; } ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully