Can I get warnings about overly-restrictive type s

2020-07-05 06:11发布

问题:

Can GHC or some lint tool tell me when I've provided a type signature for a function that could be more polymorphic?

回答1:

GHC doesn't do this, and a quick search of Hackage turns up nothing.

A simple, but possibly quite effective way to implement such a thing would be to load the module in GHCi, use :browse to get all the type signatures, then load a copy without any type signatures, use :browse again, and compare the two outputs; then just print all the lines that differ beyond parentheses, whitespace and alpha-renaming. However, this wouldn't work perfectly, especially if you have definitions whose types can't be inferred.

I have a feeling such a tool would turn up a lot of false positives in practice.



标签: haskell ghc