2017-06-12 28 views
0

爲什麼以下不是類型檢查(coq-8.5pl3)?模式匹配似乎忘記了uv具有相同的類型。在同一索引處使用兩個感應類型值匹配的模式

Inductive X : Type -> Type := 
| XId : forall a, X a -> X a 
| XUnit : X unit. 

Fixpoint f {a : Type} (x : X a) (y : X a) : a := 
    match x, y with 
    | XId _ u, XId _ v => f u v 
    | XUnit, _ => tt 
    | _, XUnit => tt 
    end. 

錯誤消息:

Error: 
In environment 
f : forall a : Type, X a -> X a -> a 
a : Type 
x : X a 
y : X a 
T : Type 
u : X T 
y0 : X T 
T0 : Type 
v : X T0 
The term "v" has type "X T0" 
while it is expected to have type "X T". 
+2

嘗試搜索 「護航模式」[上SO](https://stackoverflow.com/search?tab=newest&q=%5bcoq%5d%20convoy%20pattern)或[CPDT](HTTP:/ /adam.chlipala.net/cpdt/html/MoreDep.html) –

+0

這就是我一直在尋找的。謝謝! –

回答

2

感謝「護航模式」的安東Trunov的提示,我設法讓那一個編譯版本。

Fixpoint f {a : Type} (x : X a) : X a -> a := 
    match x in X a return X a -> a with 
    | XId b u => fun y => match y in X b return X b -> b with 
         | XId c v => fun u => f u v 
         | XUnit => fun _ => tt 
         end u 
    | XUnit => fun _ => tt 
    end. 
相關問題