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.