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

Weird behaviour for testing equality on Dict #669

Closed
bzf opened this Issue Jul 18, 2016 · 5 comments

Comments

Projects
None yet
4 participants
@bzf

bzf commented Jul 18, 2016

There seems to be something weird when testing equality on the Dict type.
Depending on how you construct the Dict, the result might vary.

Consider these values:

> foo = Dict.fromList [(1,1), (2,2)]
Dict.fromList [(1,1),(2,2)] : Dict.Dict number number'
> bar = Dict.fromList [(2,2), (1,1)]
Dict.fromList [(1,1),(2,2)] : Dict.Dict number number'

Since we're comparing the Dict I would expect that these to Dicts are
equal. However when trying this in the elm-repl that does not seem to be the
case.

> foo == bar
False : Bool

If we create another value baz, built the same way as foo, they will be
considered equal.

> baz = Dict.fromList [(1,1), (2,2)]
Dict.fromList [(1,1),(2,2)] : Dict.Dict number number'
> foo == baz
True : Bool

If I look at the documentation for Dict on core/3.0.0
there is a warning that says

Dictionary equality with (==) is unreliable and should not be used.

When reading the docs for Dict on core/4.0.3 it
seems to be missing. Maybe this is by mistake?

I'm running version 0.17.0 (got it by running elm-repl --version).

Full session:

$ elm-repl
---- elm repl 0.17.0 -----------------------------------------------------------
 :help for help, :exit to exit, more at <https://github.com/elm-lang/elm-repl>
--------------------------------------------------------------------------------
> import Dict
> foo = Dict.fromList [(1,1), (2,2)]
Dict.fromList [(1,1),(2,2)] : Dict.Dict number number'
> bar = Dict.fromList [(2,2), (1,1)]
Dict.fromList [(1,1),(2,2)] : Dict.Dict number number'
> foo == bar
False : Bool
> baz = Dict.fromList [(1,1), (2,2)]
Dict.fromList [(1,1),(2,2)] : Dict.Dict number number'
> foo == baz
True : Bool
@process-bot

This comment has been minimized.

Show comment
Hide comment
@process-bot

process-bot Jul 18, 2016

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

process-bot commented Jul 18, 2016

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Jul 18, 2016

Member

What version of core are you using? It was fixed in 4.0.3, but is still weird before that.

Member

evancz commented Jul 18, 2016

What version of core are you using? It was fixed in 4.0.3, but is still weird before that.

@bzf

This comment has been minimized.

Show comment
Hide comment
@bzf

bzf Jul 18, 2016

@evancz Checking my exact-dependencies.json it seems to be "elm-lang/core": "4.0.1". After upgrading to 4.0.3 it seems to work as expected, thanks!

bzf commented Jul 18, 2016

@evancz Checking my exact-dependencies.json it seems to be "elm-lang/core": "4.0.1". After upgrading to 4.0.3 it seems to work as expected, thanks!

@bzf bzf closed this Jul 18, 2016

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Jul 18, 2016

Member

Great, glad it's working!

Member

evancz commented Jul 18, 2016

Great, glad it's working!

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Jul 19, 2016

Contributor

To be on the safe side regarding the future, I've proposed addition of the above case to the test suite: https://github.com/elm-lang/core/pull/670. There wasn't such a test yet.

Contributor

jvoigtlaender commented Jul 19, 2016

To be on the safe side regarding the future, I've proposed addition of the above case to the test suite: https://github.com/elm-lang/core/pull/670. There wasn't such a test yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment