Can I get warnings about overly-restrictive type signatures?

我们两清 提交于 2019-12-12 08:23:14

问题


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.



来源:https://stackoverflow.com/questions/9986508/can-i-get-warnings-about-overly-restrictive-type-signatures

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!