Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Local Universes in Sections?

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Local Universes in Sections?


Chronological Thread 
  • From: Gregory Malecha <gmalecha AT gmail.com>
  • To: Coq Club <coq-club AT inria.fr>
  • Subject: Re: [Coq-Club] Local Universes in Sections?
  • Date: Fri, 27 Nov 2015 10:26:24 -0800
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=gmalecha AT gmail.com; spf=Pass smtp.mailfrom=gmalecha AT gmail.com; spf=None smtp.helo=postmaster AT mail-yk0-f180.google.com
  • Ironport-phdr: 9a23:d05WdBxyh5ZolNTXCy+O+j09IxM/srCxBDY+r6Qd0e0WIJqq85mqBkHD//Il1AaPBtWGraIfwLeM+4nbGkU+or+5+EgYd5JNUxJXwe43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6anHS+4HYoFwnlMkItf6KuStOU35/8irr60qaQSjsLrQL1Wal1IhSyoFeZnegtqqwmFJwMzADUqGBDYeVcyDAgD1uSmxHh+pX4p8Y7oGx48sgs/M9YUKj8Y79wDfkBVGxnYCgJ45jAsgCLZg+S7DNIWWIP1xFMHgLt7RfgX563vDGs5cRn3yzPEtf7QrcuSHyH5qNmQx/hwHMIMjc9/WrXg+R/iatapFSqoBkpkN2cW52cKPcrJvCVRtgdX2cUG58JDyE=

This is great. Thanks, Matthieu. I should have looked at the new documentation.

On Thu, Nov 26, 2015 at 3:47 AM, Matthieu Sozeau <mattam AT mattam.org> wrote:
Hi Gregory,

  if you put yourself in Universe Polymorphism mode or prefix the following Universes command with [Polymorphic] you can get what you expect:

Section pmap.
  Polymorphic Universes i j.
  Variable T : Type@{i}.
  Variable U : Type@{j}.
  Variable f : T -> U.
  Polymorphic Fixpoint pmap (ls : plist@{i} T) : plist@{j} U :=
    match ls with
    | pnil => pnil
    | pcons l ls => pcons (f l) (pmap ls)
    end.
End pmap.

pmap@{Top.105 Top.106} :
forall (T : Type@{Top.105}) (U : Type@{Top.106}),
(T -> U) -> plist@{Top.105} T -> plist@{Top.106} U
(* Top.105 Top.106 |= Set <= Top.105
                      Set <= Top.106
                       *)

  This is all documented in the reference manual.
Best,
-- Matthieu

On Wed, Nov 25, 2015 at 8:41 AM Gregory Malecha <gmalecha AT gmail.com> wrote:
Hello --

I've been playing with the new universe polymorphism code in 8.5 and it is great, but I'm wondering if there is any way to declare a universe in a section and have them "cooked" at the end?

Thanks a lot.

Here is a concrete example. Suppose that I have polymorphic lists.

Set Printing Universes.

Polymorphic Inductive plist@{i} (T : Type@{i}) : Type@{i} :=
| pnil
| pcons : T -> plist T -> plist T.

Arguments pnil {_}.
Arguments pcons {_} _ _.

And I'd like to write the polymorphic map function. Normally (without polymorphism) I would use sections like this since the termination checker does better with this:

Section pmap.
  Variable T : Type.
  Variable U : Type.
  Variable f : T -> U.
  Polymorphic Fixpoint pmap (ls : plist T) : plist U :=
    match ls with
    | pnil => pnil
    | pcons l ls => pcons (f l) (pmap ls)
    end.
End pmap.

However, this gives me a quite strange definition.

About pmap.
(*
pmap@{Top.9 Top.13} :
forall (T : Type@{Top.7}) (U : Type@{Top.8}),
(T -> U) -> plist@{Top.9} T -> plist@{Top.13} U
(* Top.9 Top.13 |= Set <= Top.9
                   Set <= Top.13
                   Top.7 <= Top.9
                   Top.8 <= Top.13
                    *)
*)

What I'd like to get is something like this:

Polymorphic Definition pmap'@{i j} {T : Type@{i}} {U : Type@{j}} (f : T -> U)
  : plist@{i} T -> plist@{j} U :=
  fix pmap ls :=
    match ls with
    | pnil => pnil
    | pcons l ls => pcons (f l) (pmap ls)
    end.

Which has exactly the definition that I want.

About pmap'.
(*
pmap'@{i j} :
forall (T : Type@{i}) (U : Type@{j}), (T -> U) -> plist@{i} T -> plist@{j} U
(* i j |= Set <= i
          Set <= j
           *)

pmap' is universe polymorphic
Arguments T, U are implicit and maximally inserted
Argument scopes are [type_scope type_scope _ _]
pmap' is transparent
Expands to: Constant Top.pmap'
*)

Unfortunately, it can be quite annoying to write a bunch of functions out like this explicitly. The problem seems to come from the inability to name the universes in the types of T and U and continue using them later in the section.

--
gregory malecha



--
gregory malecha



Archive powered by MHonArc 2.6.18.

Top of Page