coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Bas Spitters <spitters AT cs.ru.nl>
- To: Adam Megacz <megacz AT cs.berkeley.edu>
- Cc: Coq Club <coq-club AT inria.fr>
- Subject: Re: [Coq-Club] Notation which uses parameters of a Record/Class?
- Date: Wed, 14 Apr 2010 09:17:54 +0200
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type :content-transfer-encoding; b=Ud2dcKZAahFWR0kYE5vulmnmq7Kd7BGJONjSHHLaYYrFTPo6f5+HP1VskzJQaLG1GB Oq7Jv3JFea+xmXCjPM4/fv7i+CGVOZmbuebEgb38d/ijpgbAjbnI7pSCKwt2pI/oOUIq IouwJEDBbpKiCTShHWmHn3jRbY/V6zd8mJ+TY=
Our solution is to first define an "operational type class"
E.g.
Class SemiGroupOp A := sg_op: A → A → A.
Infix "&" := sg_op (at level 50, left associativity).
[
It would be nicer to write:
Class SemiGroupOp A := (&) : A → A → A.
Like in haskell.
]
and then:
Context A {e: Equiv A}.
Class Setoid: Prop := setoid_eq:> Equivalence (@equiv A e).
Class SemiGroup {op: SemiGroupOp A}: Prop :=
{ sg_setoid:> Setoid
; sg_ass:> Associative sg_op
; sg_mor:> Proper (e ==> e ==> e)%signature sg_op }.
Class Monoid {op: SemiGroupOp A} {unit: MonoidUnit A}: Prop :=
{ monoid_semigroup:> SemiGroup
; monoid_left_id:> LeftIdentity sg_op mon_unit
; monoid_right_id:> RightIdentity sg_op mon_unit }.
Class Group {op: SemiGroupOp A} {unit: MonoidUnit A} {inv: GroupInv
A}: Prop :=
{ group_monoid:> Monoid
; inv_proper:> Proper (e ==> e) inv
; ginv_l: `(- x & x = mon_unit)
; ginv_r: `(x & - x = mon_unit) }.
This is described in our ITP "rough diamond" which, together with the
sources, is available at:
http://www.xs4all.nl/~weegen/eelis/research/math-classes/
We are currently working on a fuller version of this paper and the
development.
Bas
On Wed, Apr 14, 2010 at 6:06 AM, Adam Megacz
<megacz AT cs.berkeley.edu>
wrote:
>
> Is there any way to have a [Notation] whose definition involves
> parameters of the Record/Class currently being defined?
>
> Example:
>
> Â Class Monoid (Carrier:Set)(mult:Carrier->Carrier->Carrier) :=
> Â { neutral : Carrier
> Â ; identL Â : forall a, Â Â (mult a neutral) = a
> Â ; identR Â : forall a, Â Â (mult neutral a) = a
>  ; assoc  : forall a b c, (mult a (mult b c)) = (mult (mult a b) c)
> Â }.
>
> I would much rather write this (especially for classes which are more
> complicated than a simple Monoid), but Coq won't accept it:
>
> Â Reserved Notation "a ** b" (at level 50).
> Â Class Monoid (Carrier:Set)(mult:Carrier->Carrier->Carrier) :=
> Â { neutral : Carrier
> Â ; identL Â : forall a, Â Â a**neutral = a
> Â ; identR Â : forall a, Â Â neutral**a = a
>  ; assoc  : forall a b c, a**(b**c) = (a**b)**c
> Â } where "a ** b" := (mult a b).
>
> I tried putting the 'where "a ** b" := (mult a b)' in a few other places
> to no avail. Â Unfortunately due to other constraints I can't just add a
> new field and a notation for it, like this:
>
> Â Class Monoid (Carrier:Set)(mult:Carrier->Carrier->Carrier) :=
> Â { mult_again := mult where "a ** b" := (mult_again a b)
> Â ...
> Â }
>
> By the way, the definition above is technically illegal according to the
> Coq manual (you're not supposed to be able to put "where" after a ":="
> clause according to a strict reading of the BNF) but Coq 8.2pl3 accepts
> it anyways. Â Not sure if the BNF should be more permissive or Coq should
> be stricter.
>
> Thanks,
>
> Â - a
>
>
- [Coq-Club] Notation which uses parameters of a Record/Class?, Adam Megacz
- Re: [Coq-Club] Notation which uses parameters of a Record/Class?, Bas Spitters
- Re: [Coq-Club] Notation which uses parameters of a Record/Class?, AUGER Cédric
- Message not available
- [Coq-Club] Re: Notation which uses parameters of a Record/Class?,
Adam Megacz
- Re: [Coq-Club] Re: Notation which uses parameters of a Record/Class?, Bas Spitters
- Re: [Coq-Club] Re: Notation which uses parameters of a Record/Class?, AUGER Cédric
- Message not available
- [Coq-Club] Re: Notation which uses parameters of a Record/Class?,
Adam Megacz
Archive powered by MhonArc 2.6.16.