coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Arnaud Spiwack <aspiwack AT lix.polytechnique.fr>
- To: Anders Lundstedt <anders AT anderslundstedt.se>
- Cc: Coq Club <coq-club AT inria.fr>
- Subject: Re: [Coq-Club] Notation for partial terms
- Date: Mon, 13 Jan 2014 09:40:59 +0100
You could do something along the following line (caveat below the example)
The implicit coercion mechanism of Coq only works with specific types, i.e. there is no way to specify that Some is a coercion from X to option X in general. I find it's often a pity. So here, the example works because we have fixed a type A. If you are not in this sweet spot, you will have to either manually write Some for every atom:
You can also give a notation for Some which will make this _expression_ slimmer, but you will have to write something.
Arnaud
Definition extension2 {A} (f:A->A->option A) (x y:option A) : option A :=
match x , y with
| Some x' , Some y' => f x' y'
| _ , _ => None
end
.
Parameter A : Type.
Parameter f : A -> A -> option A.
Definition retA : A -> option A := @Some A.
Coercion retA : A >-> option.
Notation "a * b" := (extension2 f a b).
Check forall a b c d x, a * b * c * d = x.
match x , y with
| Some x' , Some y' => f x' y'
| _ , _ => None
end
.
Parameter A : Type.
Parameter f : A -> A -> option A.
Definition retA : A -> option A := @Some A.
Coercion retA : A >-> option.
Notation "a * b" := (extension2 f a b).
Check forall a b c d x, a * b * c * d = x.
The implicit coercion mechanism of Coq only works with specific types, i.e. there is no way to specify that Some is a coercion from X to option X in general. I find it's often a pity. So here, the example works because we have fixed a type A. If you are not in this sweet spot, you will have to either manually write Some for every atom:
Check forall a b c d x, Some a * Some b * Some c * Some d = x.
You can also give a notation for Some which will make this _expression_ slimmer, but you will have to write something.
Arnaud
On 13 January 2014 08:40, Anders Lundstedt <anders AT anderslundstedt.se> wrote:
Dear all,given a partial binary operationf : A -> A -> option Ais there a convenient way to write partial expressions (with left associativity)? I would like to be able to write e.g.a*b*c*dwhich would be equal to Some e ifa*b=Some xx*c=Some yy*d=Some efor some x y : A, otherwise we would have a*b*c*d = None.Best regards,Anders Lundstedt
- [Coq-Club] Notation for partial terms, Anders Lundstedt, 01/13/2014
- Re: [Coq-Club] Notation for partial terms, Arnaud Spiwack, 01/13/2014
- Re: [Coq-Club] Notation for partial terms, Cedric Auger, 01/13/2014
- Re: [Coq-Club] Notation for partial terms, Anders Lundstedt, 01/13/2014
Archive powered by MHonArc 2.6.18.