替换=>代替 - >在函数类型签名中 [英] Replacing => in place of -> in function type signature
本文介绍了替换=>代替 - >在函数类型签名中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚才注意到,如果不是 - >
,我在类型签名定义中写入 =>
的函数,它不会导致编译时错误。示例代码:
mysum :: Num a => [a] => a - Notice =>在列表[a]
mysum [] = 0
之后[mysum xs] = x + mysum xs
为什么会发生这种情况?有没有办法避免这种情况?
使用的编译器:GHC 7.6.2
更新:在 ideone 中成功编译。
解决方案
这是GHC 7.6.2中的一个错误。你应该在最近的编译器中尝试它,如果它仍然没有提供错误,那么你应该提交一个错误报告。
其实,我认为这个bug已经在GHC 7.8中已知和修复。I just observed that if instead of ->
, I write =>
in the type signature definition of a function, it doesn't result in an compile time error. Example code:
mysum :: Num a => [a] => a -- Notice => after the list [a]
mysum [] = 0
mysum (x:xs) = x + mysum xs
Why does this happen ? And is there a way to avoid this ?
Compiler Used: GHC 7.6.2
Update: Successful compilation in ideone.
解决方案
This is a bug in GHC 7.6.2. You should try it in the most recent compiler and if it still doesn't give an error there, then you should file a bug report.
Actually, I think this bug is already known and fixed in GHC 7.8.
这篇关于替换=>代替 - >在函数类型签名中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文