Search code examples
coqssreflect

when is the `:` (colon) in necessary in ssreflect/Coq?


I am trying to understand the exact meaning of the : (colon) in Coq/ssreflect proofs in terms of non-ssreflect Coq.

I read that it has something to do with moving things to the goal (like generalize??) and is the opposite of =>, which move things to the hypotheses. However, I often find it confusing because proofs work either way with or without the :. Below is an example from a tutorial:

Lemma tmirror_leaf2 t : tmirror (tmirror t) = Leaf -> t = Leaf.
Proof.
move=> e.
by apply: (tmirror_leaf (tmirror_leaf e)).
Qed.

where,

tmirror_leaf
     : forall t, tmirror t = Leaf -> t = Leaf

is a lemma that says if the mirror of a tree is a leaf, then the tree is a leaf.

I don't understand why we need the : here and not merely do the Coq apply. In fact, if I remove the :, it works just fine. Why does it make a difference?


Solution

  • I think I found the answer while reading the SSReflect documentation. Essentially, ssr has redefined tactics like apply such that it operates on the first variable of the goal instead of something in the context. That's why the : is used in apply: XX. in the ssr way (which is equivalent to move: XX; apply.), and it also works if : is omitted as that is the traditional Coq way.

    Quoting the documentation:

    Furthermore, SSReflect redefines the basic Coq tactics case, elim, and apply so that they can take better advantage of ':' and '=>'. These Coq tactics require an argument from the context but operate on the goal. Their SSReflect counterparts use the first variable or constant of the goal instead, so they are "purely deductive":

    they do not use or change the proof context. There is no loss since `:' can readily be used to supply the required variable.