Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] fun+pattern and primitive projections

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] fun+pattern and primitive projections


Chronological Thread 
  • From: Matthieu Sozeau <mattam AT mattam.org>
  • To: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] fun+pattern and primitive projections
  • Date: Wed, 07 Feb 2018 12:46:20 +0000
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=mattam AT mattam.org; spf=Pass smtp.mailfrom=matthieu.sozeau AT gmail.com; spf=None smtp.helo=postmaster AT mail-wr0-f181.google.com
  • Ironport-phdr: 9a23:54axSRdYoF5FzA2pT0hTH4knlGMj4u6mDksu8pMizoh2WeGdxcu6bR7h7PlgxGXEQZ/co6odzbaO6ua4ASQp2tWoiDg6aptCVhsI2409vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/NlVJSo6lPwWB6nK94iQPFRrhKAF7Ovr6GpLIj8Swyuu+54Dfbx9HiTahfL9+Ngm6oRnMvcQKnIVuLbo8xAHUqXVSYeRWwm1oJVOXnxni48q74YBu/SdNtf8/7sBMSar1cbg2QrxeFzQmLns65Nb3uhnZTAuA/WUTX2MLmRdVGQfF7RX6XpDssivms+d2xSeXMdHqQb0yRD+v6bpgRh31hycdLzM2/2/Xhc5wgqxVoxyvugJxzJLPbY6PKPZzZLnQcc8GSWdDWMtaSixPApm7b4sKF+cPOvxXr5Xhp1sOrBuxGxSsD/7yxD9Ph375w7c10/k8GgzB2QwvBc4OsGjOo9XwL6oSVPq6zLXUzTrZavNawzD96JLHch04p/yHQLF+cdLJxEUxCw/Iik+cpI/lMj+Py+gBrWuW4/B9We+slmIqrRx6rCK1ycc2kIbJg5oYylDa+iV9x4Y4Pdi4R1R6Yd6gCZdRuTuaO5dvTsMsXm1luzs2xqcJuZ68eygKx5AnyADFZ/ObdIiI5wrvVOeXIThmmHJoYKyziwq2/ES6yeDxVtO43EtUoidGiNXAq3MA2wHL5siCUPR9/0Oh2TiV1wDU7+FJOUU0mrDHK549wr4wl4QcsVnZEi/tn0X3jbGZeV85+uWz5OTnZ6/ppp6YN4Nulg7+NaEultSlAeskKggOQ3Sb+eOk2bL/+k35WaxGgeEykqnEq5/XPt8bp668Aw9NyIkv8Re/DzG80NQZh3YLNlxFeAjUx7TublrJObXzCeq1q1WqijZigf7cbZP7BZCYC3HfjLfgcKs10ElOxQMuhYRa7o5IA7QpJfvvRkb08tvCAUlqYESP3+/7BYAlhcslUmWVD/rBafKAgRqz/usqZtK0SsoQsTf5JeIi4qe333A8kF4ZO6Ku2MlOMSzqLrFdO0ycJEHUrJIZC25T5Fg7RfD2gVjEViRcNS7rAvAMowojAYfjNr/tA4CghLvbgnW+F5xSI39cUhWCSCexMYqDXPgIZWSZJcozyjE=

Hi,

It think it would be rather hopeless to try and invert the projections at pretty printing time to everyone’s contentment. However, it might be possible to use a more clever desugarring that let-binds the projections (potentially with specific constants to avoid simpl reducing them but still allowing unification to succeed) and invert those.
Cheers,
— Matthieu
Le mer. 7 févr. 2018 à 13:26, Armaël Guéneau <armael.gueneau AT ens-lyon.fr> a écrit :
Hi everyone,

I am facing an issue related to the use of "fun '(_,_) => ..." with
primitive projections. It works well when writing goals & lemmas, but
at pretty-printing time, only the desugared version is printed, which
quickly gets unreadable. I'm wondering if other people have already
faced this issue, and if there's a known workaround to improve the
pretty-printing -- or if I should maybe open a feature request on
Coq's issue tracker.



Here follows a more detailed description of the issue.

Let's assume for the sake of the example a predicate on functions of
type "A -> nat", and a compatibility lemma about P and +, which holds
for any A.

  Parameter P : forall A, (A -> nat) -> Prop.
  Hypothesis P_add : forall A f g,
    P A f -> P A g -> P A (fun x => f x + g x).

Now consider the following goal, where A is (nat * nat):

  Goal P (nat * nat) (fun '(x,y) => x + y).
    Fail apply P_add.

With the standard pairs, I cannot call "apply P_add" -- the goal does
not unify with the conclusion of the lemma, since (fun '(x,y) => x +
y) is sugar for (fun p => let (x,y) := p in x + y). One solution would
be to restate the goal as:

  Goal P (nat * nat) (fun p => (fst p) + (snd p)).
    apply P_add

which I find inconvienient; I like being able to give names to the
components of the tuple, especially with bigger arities (where one
would have to instead write (fst (fst p)) and such).


Matthieu Sozeau pointed out to me that an other solution is to use
primitive projections: this way, one can still use the "fun '(x,y) =>
..." sugar, which gets desugared to uses of fst and snd.

  Set Primitive Projections.
  Unset Printing Primitive Projection Compatibility.
  (* required for projections to actually be displayed *)

  Record myprod A B := mypair { myfst : A; mysnd : B }.

  Arguments mypair {A B} _ _.
  Arguments myfst {A B} _.
  Arguments mysnd {A B} _.

  Notation "x ** y" := (myprod x y) (at level 80): type_scope.
  Notation "( x , y , .. , z )" := (mypair .. (mypair x y) .. z).

  Goal P (nat ** nat) (fun '(x,y) => x + y).
    apply P_add.

This works, which is nice. (fun '(x,y) => x + y) is desugared to (fun
pat : nat ** nat => (myfst pat) + (mysnd pat)), and P_add can be
applied directly.

However, this desugaring is made apparent to the user: when proving
the goal, the user works with the desugared version of the goal &
hypothesis. This quickly gets unreadable in my opinion: there's a
"pat" variable that I cannot name, the names "x" and "y" are lost, and
with tuples of arity > 2, they are replaced by nested projections (eg
(fst (fst pat))) which I find really hard to keep track of.

I'm wondering if someone already faced this issue.
If there is no workaround for now, could one think of a better
pretty-printer? I'm thinking of attaching to a "fun" the fact that it
comes from a "fun '(_,_) => ..." sugar, along with information about
the user-provided names; and then trying to pretty-print the
fun+projections using the "fun '(_,_) => ..." sugar and the user
names.

If this seems a reasonable proposal I could submit a feature request
on Coq's issue tracker.


Cheers, and thanks for reading,
Armaël



Archive powered by MHonArc 2.6.18.

Top of Page