Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Program and non-exhaustive pattern matching

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Program and non-exhaustive pattern matching


Chronological Thread 
  • From: Arthur Azevedo de Amorim <arthur.aa AT gmail.com>
  • To: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] Program and non-exhaustive pattern matching
  • Date: Fri, 18 Mar 2016 15:24:39 +0000
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=arthur.aa AT gmail.com; spf=Pass smtp.mailfrom=arthur.aa AT gmail.com; spf=None smtp.helo=postmaster AT mail-oi0-f43.google.com
  • Ironport-phdr: 9a23:P0wrKRf7giDMZFzne2RjjUVrlGMj4u6mDksu8pMizoh2WeGdxc6+bR7h7PlgxGXEQZ/co6odzbGG4+a4BCdZsMnJmUtBWaIPfidNsd8RkQ0kDZzNImzAB9muURYHGt9fXkRu5XCxPBsdMs//Y1rPvi/6tmZKSV3BPAZ4bt74BpTVx5zukbviq9uLPk4R1WX1SIgxBSv1hD2ZjtMRj4pmJ/R54TryiVwMRd5rw3h1L0mYhRf265T41pdi9yNNp6BprJYYAu2pN5g/GLdfFXEtN30/zMztrxjKCwWVtVUGVWBDuwBUAxXfpDjoU4n8viyyuuc18SydJ8zzBeQ9Qyii8r0tQRbAhyIONjp/+2bS3J8jxJlHqQ6s8kQsi7XfZ5uYYaJz

Hello Pierre,

Your code seems to work under 8.4 (if we replace Variant with Inductive):

Require Import Program.

Inductive Is_Some {A} : option A -> Prop :=
| Is_some a : Is_Some (Some a).

Program Definition from_Some A (x : option A | Is_Some x) : A :=
   match x with
     | (Some a) => a
     | None => _
   end.

Next Obligation.
   apply False_rect. inversion H.
Qed.

From your error message, it seems that you're having some issue with universe levels. What's interesting is that, in 8.5, if we write the term that Coq is complaining about by hand, no error message appears:

Variant Is_Some {A} : option A -> Prop :=
| Is_some a : Is_Some (Some a).

Check (fun A (x : { x : option A | Is_Some x })  => proj1_sig x).



Em sex, 18 de mar de 2016 às 09:41, Pierre Néron <pierre.neron AT polytechnique.org> escreveu:
Hi,

I'm trying to use Program to define some kind of non-exhaustive pattern
matching.
For example I want to define a function from_Some : (x : option A |
"is_some x" ) -> A

Require Import Program.

Variant Is_Some {A} : option A -> Prop :=

| Is_some a : Is_Some (Some a).

Program Definition from_Some A (x : option A | Is_Some x) : A :=

   match x with

     | (Some a) => a

     | None => _

   end.

Next Obligation.

   apply False_rect. inversion H.

Fail Qed.

I can't understand why coq fails here with the following message:

The command has indeed failed with message:

Illegal application:

The term "proj1_sig" of type

  "forall (A : Type) (P : A -> Prop), {x : A | P x} -> A"

cannot be applied to the terms

  "option A" : "Type"

  "fun x : option A => Is_Some x" : "option A -> Prop"

  "x" : "{x : option A | Is_Some x}"

The 1st term has type "Type@{max(Set, Top.25)}" which should be coercible to

  "Type@{Coq.Init.Specif.16}".

  I managed to get around this problem by defining the following function:

Program Definition from_Some1 A (x : option A | Is_Some x) : A :=

   (match x as o return Is_Some o -> A with

     | (Some a) => fun _ => a

     | None => fun _ => !

   end) _.

Next Obligation of from_Some1.

   inversion H.

Qed.

but I would like to understand why the first definition fails.

Thanks in advance

--
Pierre.




Archive powered by MHonArc 2.6.18.

Top of Page