ndmitchell / hlint

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

Warn about partial functions #420

Open mjepronk opened 6 years ago

mjepronk commented 6 years ago

Would it be an idea if HLint would warn about partial functions like head?

Of course the list should be hardcoded (since there is no way to automatically identify them).

I couldn't find if this has been discussed previously, so sorry if it was.

ndmitchell commented 6 years ago

It seems reasonable, however, I've resisted for a few reasons:

ndmitchell commented 6 years ago

Solution is to have a group in .hlint.yaml which is off by default, then people can turn on a warning of groups of partial functions. I'm happy for someone to contribute this.

ndmitchell commented 6 years ago

Probably good to start with the list in https://wiki.haskell.org/Avoiding_partial_functions

anka-213 commented 4 years ago

I think one important distinction to make is partial pure functions and partial impure functions. If you're in IO, you'll probably expect operations to fail, not as much so in pure code. readFile is kind of a corner-case though, since it is lazyIO, which can cause crashes in pure code.

ndmitchell commented 4 years ago

Having a warning for lazy-IO functions as a separate set would be possible. I leave it to what people want to contribute.