ndmitchell / hlint

Haskell source code suggestions
Other
1.47k stars 196 forks source link

Move guards forward breaks code using GADTs #1175

Open expipiplus1 opened 3 years ago

expipiplus1 commented 3 years ago

Consider that matching on Foo brings some constraints into scope which are required by baz

    x = [ () | Foo <- bar @s, let s = baz ]

Hlint changes things thusly:

    x = [() | let s = baz, Foo <- _]

And the constraint is no longer in scope.

This is obviously quite uncommon so I'm not sure what the protocol is here, I'm perfectly happy disabling this lint.

(It also ate the bar @s expression when applying this automatically, but I guess that should be a separate issue (Looks similar to this: https://github.com/lspitzner/brittany/pull/324#issuecomment-727607154)

ndmitchell commented 3 years ago

Great counter example! So I guess we have to figure out how often this happens (is it super rare, or merely just rare) and if it's more than super-rare I suspect this hint needs disabling.

expipiplus1 commented 3 years ago

Obviously a substantial project: I wonder how much could be learned by applying hints over all of (compiling) Hackage and seeing what stops compiling.

ndmitchell commented 3 years ago

Before we had apply refactor there wasn't really any realistic chance of doing it. Now it seems like it would be pretty interesting.