我可以收到关于过分限制类型签名的警告吗? [英] Can I get warnings about overly-restrictive type signatures?

查看:114
本文介绍了我可以收到关于过分限制类型签名的警告吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我为一个可能更多态的函数提供了一个类型签名时,GHC或者一些lint工具能告诉我什么? 解决方案

GHC不会这样做,并且快速搜索Hackage什么都没有。



一个简单但可能相当有效的实现这种事情的方法是在GHCi中加载模块,使用:browse 获取所有类型签名,然后加载没有任何类型签名的副本,使用:browse code>,然后比较两个输出;那么只需打印所有不同于括号,空格和字母重命名的行。但是,这并不完美,特别是如果你有定义的类型无法推断。



我觉得这样的工具会变成很多在实践中误报。

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

解决方案

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.

这篇关于我可以收到关于过分限制类型签名的警告吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆