Haskell无法访问的代码错误? [英] Haskell Inaccessible code bug?
本文介绍了Haskell无法访问的代码错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说我有以下(错误)代码。
Say I have the following (erroneous) code.
data A a b where
APure :: (A a b)
AApply :: A (A b c) c
test :: (A a b) -> a -> b
test (APure) a = a
test AApply a = undefined
GHC会给我这个错误:
GHC will then give me this error:
Couldn't match type `b' with `A b1 b'
`b' is a rigid type variable bound by
the type signature for test :: A a b -> a -> b
Inaccessible code in
a pattern with constructor
AApply :: forall c b. A (A b c) c,
in an equation for `test'
In the pattern: AApply
In an equation for `test': test AApply a = undefined
这个错误消息是不是完全错误?
错误与AApply无关。
Isn't this error message completely wrong? The error has nothing to do with AApply.
推荐答案
消息完全错了?该错误与
AApply
无关。
不完全。这可能是一个错误,你得到的错误消息,但它不是完全脱离基地。
Not completely. It's arguably a bug that you get that error message, but it's not completely off base.
看完整个东西后看看这些片段。
Look at the whole thing together after looking at the pieces.
test (APure) a = a
说我们有一个函数
test :: A a b -> r -> r
将签名加在一起
test :: (A a b) -> a -> b
和unify,忽略第一个方程式的类型错误,类型精炼为
and unify, ignoring the type error from the first equation, the type is refined to
test :: A r r -> r -> r
然后查看方程式
test AApply a = undefined
精细类型,因为
AApply :: A (A b c) c
需要
c ~ A b c
如果 AApply
是有效的第一个参数。
if AApply
were a valid first argument.
这篇关于Haskell无法访问的代码错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文