Skip to Content.
Sympa Menu

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

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

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


Chronological Thread 
  • From: Pierre Néron <pierre.neron AT polytechnique.org>
  • To: coq-club AT inria.fr
  • Subject: [Coq-Club] Program and non-exhaustive pattern matching
  • Date: Fri, 18 Mar 2016 14:21:59 +0100
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=pierre.neron AT gmail.com; spf=Pass smtp.mailfrom=pierre.neron AT gmail.com; spf=None smtp.helo=postmaster AT mail-wm0-f54.google.com
  • Ironport-phdr: 9a23:spJ+7Rz3THRE75vXCy+O+j09IxM/srCxBDY+r6Qd0e4eIJqq85mqBkHD//Il1AaPBtWLraoZwLOJ6OjJYi8p39WoiDg6aptCVhsI2409vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/NlVJSo6lPwWB6kO74TNaIBjjLw09fr2zQd6CyZzqnLntoNX6WEZhunmUWftKNhK4rAHc5IE9oLBJDeIP8CbPuWZCYO9MxGlldhq5lhf44dqsrtY4q3wD86Fpy8kVWqLjOq88ULZwDTI8Mmlz6te4mwPESF6353YGSGghtJtSBA6NuAn7U43rv238u/B63gGCOsnnUb0/WTKj9rpmDhjyh3FUZHYC7GjLh5ko3+pgqxW7qkknzg==

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