Hi,
I've got a function that takes data and either returns the same data or a slightly modified version.
I want to have my program do one thing if it changed or another thing if it did not change.
Previously I was returning a pair (Bool,Object)
and using fst
to check if it changed. Lately it occurred to me that I could simplify the code by just returning the object and checking equality using ==
.
But then I realized that Haskell doesn't differentiate between deep equality checking and "object identity" (i.e., pointer equality). So how can I know whether using ==
is going to be efficient or not? Should I avoid it for efficiency reasons, or are there cases where I can depend on the compiler figuring out that it doesn't need to do a deep equality check?
Normally I wouldn't be too worried about efficiency while writing an initial program, but this affects the interface to my module so I want to get it right before writing too much code, and it doesn't seem worth it to make the program much less efficient just to simply a small piece of code. Moreover, I'd like to get a better idea of what kind of optimizations I can depend on GHC to help me with.