Giter Site home page Giter Site logo

Comments (2)

harrysarson avatar harrysarson commented on September 14, 2024 1
> JE.object [ ("a", JE.list identity []) ] == JE.object []
True : Bool
> JE.object [ ("a", JE.object []) ] == JE.object []
True : Bool

These two happen because we (after some recursion into the objects) call __Utils_eq([], undefined, depth, stack). We do not enter the if here https://github.com/elm/core/blob/65cea00afa0de03d7dda0487d964a305fc3d58e3/src/Elm/Kernel/Utils.js#L34 because x is an object (y isn't). Then we look at all the properties of [] and there are not any so we say the two objects are equal.

The fix is to check if y is an object in https://github.com/elm/core/blob/65cea00afa0de03d7dda0487d964a305fc3d58e3/src/Elm/Kernel/Utils.js#L34.

> JE.object [ ("a", JE.null) ] == JE.object [ ( "a", JE.null ), ( "b", JE.null ) ]
True : Bool

This one happens because we ignore any properties of the right hand side that are not also properties of the left hand side [1].

The fix is to compare the number of properties of x and y (using an Object.keys polyfill probably).

[1]

The code was probably written only thinking about elm records where the compiler ensures the properties of the left and right hand sides are the same or elm custom types where either the properties are the same or the value '$' of will be different.

from json.

harrysarson avatar harrysarson commented on September 14, 2024

There is one more case

> JE.object [ ] == JE.list identity []
True : Bool

Maybe it is okay to say these two are equal? After all they have all the same properties (!) Otherwise we would need a defensive check Array.isArray(x) == Array.isArray(y) (polyfilled).

All of this does seem wasteful; we would pay a cost for every (not special cased by compiler) equality in elm to make Json.Encode.Value equality work. I suspect no one much uses Json.Encode.Value equality anyway although I have no data to back that theory up.

from json.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.