Ich versuche, ein Beispiel aus CPDT aus dem Speicher zu re-implementieren. Ich schrieb:Coq-Typ Fehler beim Abgleich mit Typ Familie
Inductive myType : Set := MyNat | MyBool.
Definition typeDenote (t : myType) : Set :=
match t with
| MyNat => nat
| MyBool => bool
end.
Inductive unaryOp : myType -> myType -> Set :=
| Twice : unaryOp MyNat MyNat.
Definition twice (n:nat) : nat := n + n.
Definition tunaryDenote (a b : myType) (t : unaryOp a b)
: typeDenote a -> typeDenote b :=
match t with
| Twice => twice
end.
Der resultierende Fehler ist:
Toplevel input, characters 125-130
> | Twice => twice
> ^^^^^
Error: In environment
a : myType
b : myType
t : unaryOp a b
The term "twice" has type "nat -> nat" while it is expected to have type
"forall H : typeDenote ?141, typeDenote ?142"
Ich verstehe nicht, diese Fehlermeldung. Ich würde denken, dass, sobald das Spiel auf Twice : unaryOp MyNat MyNat
erfolgreich ist, Coq schließt, dass a
und b
sind MyNat
s, und damit typeDenote a -> typeDenote b ≡ nat -> nat
, machen twice
eine perfekte Kandidat für den Rückgabewert. Wo bin ich falsch gelaufen?
Ihre Analyse am Ende sieht vollkommen gut aus, also habe ich Ihr Stück Code genau so versucht, wie es ist, aber Coq hat sich überhaupt nicht beschwert (geprüft mit Coq v8.4pl6 und v8.5pl2). –