It would leak implementation details. Let’s imagine we have this equalByReference : a -> a -> Bool and a type Box = Box String. Currently, in 0.18, equalByReference (Box "foo") (Box "foo") == False - constructing a boxed type like that results in two distinct JS objects. However, what if the compiler was made smarter and passed those values around as raw strings instead? Now, depending on whether that optimization exists and is enabled, the equalByReference function would return different results for the same inputs.
It also means you can no longer replace any expression by a value representing that same expression while retaining the same semantics. In the above example, let boxedFoo = Box "foo" in equalByReference boxedFoo boxedFoo should yield the same result.
In short, it means losing a couple of nice properties. As an example of a language that does have such a function, in purescript this is called unsafeRefEqual. Whenever you see “unsafe”, it’s something you’re unlikely to find in Elm.
As for your original example, I don’t quite understand why it should be a reference check. Regular structural equality in Elm short-circuits for reference equality already, so if you do return the exact same thing, it would already return True very very fast. Now, if you return something that represents the same value but happens to be a new structure (perhaps you did List.map identity someVal, or unwrapped and rewrapped something), you’d end up with what would essentially be identical state.
Now, the reason that it’s okay for elm-lang/virtual-dom to use reference-equality for Html.Lazy is because it’s unobservable from within Elm. The only way to tell that it’s doing anything at all - in Elm - is to use something side-effectful (and thus impure) like Debug.log.