I had a surprising and amusing experience using Ormolu that I thought would be interesting for others to see. I was really puzzled why this code behaved incorrectly. One of the strange behaviours was that sometimes H wasn’t being printed.
"\ESC["
++ show (if wasWrapnext then oldym1 + 1 else oldym1)
++ ";"
++ if wasWrapnext then "1" else show (oldxm1 + 1)
++ "H"
After 30 minutes of trying to debug it I absent mindedly formatted with Ormolu, revealing the error. The H is part of the else branch!
"\ESC["
++ show (if wasWrapnext then oldym1 + 1 else oldym1)
++ ";"
++ if wasWrapnext
then "1"
else
show (oldxm1 + 1)
++ "H"
You’re not the only one to have run into this issue! The precedence of if...then...else syntax is unclear at best and undocumented at worst. As a heavy autoformatter I’m rhapsodic that external formatting tools behave correctly here, because in my workflow, if something is improperly formatted, it’s likely improperly written!