Redundant clause in match

风流意气都作罢 提交于 2021-02-19 05:51:43

问题


When I run the following script:

Definition inv (a: Prop): Prop :=
match a with
| False => True
| True => False
end.

I get "Error: This clause is redundant." Any idea why this happens?

Thanks, Marcus.


回答1:


There are quite a few wrong things about this.

False is not a data constructor, and since there is no syntactic difference between data constructors and variable names in Coq, it understands your | False => as a pattern matching anything and giving it the name False, in the same way as you could have written:

Definition inv (a: Prop): Prop :=
  match a with
  | x => True
  | y => False
  end.

This is why it tells you that the second clause is redundant (since the first pattern matches everything).

Now another thing you should know is that the type Prop is not inductively-defined, and therefore values of type Prop cannot be matched against anything: in fact it would not make sense, since it is an open type that you keep expanding everytime you define a new inductive property.

So there is no way to write a function inv the way you write it.



来源:https://stackoverflow.com/questions/27028360/redundant-clause-in-match

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!