/= produces inconsistent result

I have stumbled across an odd thing with (/=) operator. 1 /= 0 produces 1 and 1 /= 1 produces False. (==) works as expected with Boolean. See the Logs in the referenced ellie.

Seeing this with Elm 0.19, latest Chrome on a Mac. Is this a known issue?

https://ellie-app.com/6D4Snjzg5TGa1

I think that this is this bug: https://github.com/elm/compiler/issues/1810 and that it is fixed in 0.19.1-beta-1:

---- Elm 0.19.1 ----------------------------------------------------------------
Say :help for help and :exit to exit! More at <https://elm-lang.org/0.19.1/repl>
--------------------------------------------------------------------------------
> 1/=0
True : Bool
> 1/=1
False : Bool

Quoting Evan Czaplicki:

For the record, this is due to an optimization that relied on truthiness in JS.

@dmy thanks for pointer and good to know it will be fixed in the next release.

I think the boolean logic is still always correct though, it just looks weird when you inspect it.

No, boolean logic is not always correct.
For example (12 /= 0) == (21 /= 0) evaluates to False in Elm 0.19.

2 Likes

Thankfully that’s also (incidentally?) fixed in 0.19.1:

> (12 /= 0) == (21 /= 0)
True : Bool
1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.