coq-club AT inria.fr
Subject: The Coq mailing list
List archive
Re: [Coq-Club] Stumped by a perfectly good looking definition in Chilpala's CPDT
Chronological Thread
- From: Tej Chajed <tchajed AT mit.edu>
- To: Satrajit Roy <satrajit.roy AT gmail.com>
- Cc: coq-club <coq-club AT inria.fr>
- Subject: Re: [Coq-Club] Stumped by a perfectly good looking definition in Chilpala's CPDT
- Date: Tue, 18 Oct 2016 13:35:15 -0400
- Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=tchajed AT mit.edu; spf=Pass smtp.mailfrom=tchajed AT mit.edu; spf=None smtp.helo=postmaster AT dmz-mailsec-scanner-6.mit.edu
- Ironport-phdr: 9a23:GYWAmBWSWNH0lOYP0NTc3F+DNOzV8LGtZVwlr6E/grcLSJyIuqrYZhSAt8tkgFKBZ4jH8fUM07OQ6PG6HzFcqs/Y6jhCKMUKDEBVz51O3kQJO42sNw7SFLbSdSs0HcBPBhdO3kqQFgxrIvv4fEDYuXao7DQfSV3VPAtxIfnpSMaJ15zkn8j7wZDYYh1JiTyhevsyaUzu9USC/vUR1LBrNrw4yBrV6kFPaqwC3mp0P1uRngq6/MCh1JFm+iVU/fkm8pgTf7/9evEEQL4QJzQvMW05rJn3vhnKTwaDzn4dTiMbngceUFuN1w3zQpqk6niyjeF6wiTPeJSuFb0=
Oh, I see; that's the problem!!!Thank you Tej.But are there known situations where I could get into intractable problems using Implicit Arguments?On Tue, Oct 18, 2016 at 9:41 AM, Tej Chajed <tchajed AT mit.edu> wrote:You’re not benefitting from Coq’s implicit arguments feature, which is like automatically passing _ for the argument. If you run [Set Implicit Arguments.] before creating your inductive types and definitions Coq will add some implicit arguments automatically, which often work well - CPDT does this to get usable implicit arguments.
Your original problem seems related to a Coq bug I ran into recently (bug 5142). In order to get a better error message for buggy dependent matches you need to explicitly annotate the match statement:
Fixpoint texpDenote t (e:texp t):typeDenote t:= match e in (texp t0) return (typeDenote t0) with |TNConst n=>n |TBConst b=>b |TBinop _ _ _ b e1 e2=>(tbinop b)(texpDenote e1)(texpDenote e2) end. (* Error: In environment texpDenote : forall t : type, texp t -> typeDenote t t : type e : texp t t0 : type t1 : type t2 : type b : tbinop t0 t0 t2 e1 : texp t0 e2 : texp t1 The term "b" has type "tbinop t0 t0 t2" while it is expected to have type "type". *)
Unfortunately this return annotation is not inferred if the body has type errors, though it would be nice if it were based on the annotations on texpDenote.
On Tue, Oct 18, 2016 at 9:13 AM, Satrajit Roy <satrajit.roy AT gmail.com> wrote:It seems like a version incompatibility though, doesn't it?Now I must use ugly syntax like the following:Eval simpl in texpDenote _ (TNConst 42).
Eval simpl in texpDenote _ (TBConst true).
Eval simpl in texpDenote _ (TBinop _ _ _ TTimes (TBinop _ _ _ TPlus (TNConst 2)(TNConst 2))(TNConst 7)).
Eval simpl in texpDenote _ (TBinop _ _ _ (TEq Nat) (TBinop _ _ _ TPlus (TNConst 2) (TNConst 2))(TNConst 7)).
Eval simpl in texpDenote _ (TBinop _ _ _ TLt (TBinop _ _ _ TPlus (TNConst 2) (TNConst 2))(TNConst 7)).I remember I executed parts of CPDT before and most things worked.--On Mon, Oct 17, 2016 at 4:43 PM, Satrajit Roy <satrajit.roy AT gmail.com> wrote:Ahhh!!! Thank you so much!!--On Mon, Oct 17, 2016 at 4:18 PM, John Wiegley <johnw AT newartisans.com> wrote:>>>>> "SR" == Satrajit Roy <satrajit.roy AT gmail.com> writes:
SR> My exposure to COQ is limited; so I'm possibly not seeing something
SR> obvious. Given the following definitions, why isn't the last one working?
After a few changes, this works. What you wrote failed to type check, not
because of the TNConst case, but because the type of the term you were
creating in the TBinop case was not the correct type, and this affected the
type expected for the TNConst case.
--8<---------------cut here---------------start------------->8---
Require Import Bool.Bool Arith List.
Inductive type:Set:=Nat|Bool.
Inductive tbinop:type->type->type->Set:=
|TPlus:tbinop Nat Nat Nat
|TTimes:tbinop Nat Nat Nat
|TEq:forall t, tbinop t t Bool
|Tlt:tbinop Nat Nat Bool.
Inductive texp:type->Set:=
|TNConst:nat->texp Nat
|TBConst:bool->texp Bool
|TBinop:forall t1 t2 t, tbinop t1 t2 t->texp t1->texp t2->texp t.
Definition typeDenote(t:type):Set:=
match t with
|Nat=>nat
|Bool=>bool
end.
Definition tbinopDenote arg1 arg2 res(b:tbinop arg1 arg2 res):typeDenote
arg1->typeDenote arg2->typeDenote res:=
match b with
|TPlus=>plus
|TTimes=>mult
|TEq Nat=>beq_nat
|TEq Bool=>eqb
|TLt=>leb
end.
Fixpoint texpDenote t (e:texp t):typeDenote t:=
match e with
|TNConst n=>n
|TBConst b=>b
|TBinop _ _ _ b e1 e2=> tbinopDenote _ _ _ b (texpDenote _ e1) (texpDenote _ e2)
end.
--8<---------------cut here---------------end--------------->8---
--
John Wiegley GPG fingerprint = 4710 CF98 AF9B 327B B80F
http://newartisans.com 60E1 46C4 BD1A 7AC1 4BA2
Satrajit
Satrajit
Satrajit
- [Coq-Club] Stumped by a perfectly good looking definition in Chilpala's CPDT, Satrajit Roy, 10/17/2016
- Re: [Coq-Club] Stumped by a perfectly good looking definition in Chilpala's CPDT, John Wiegley, 10/17/2016
- Re: [Coq-Club] Stumped by a perfectly good looking definition in Chilpala's CPDT, Satrajit Roy, 10/17/2016
- Re: [Coq-Club] Stumped by a perfectly good looking definition in Chilpala's CPDT, Satrajit Roy, 10/18/2016
- Re: [Coq-Club] Stumped by a perfectly good looking definition in Chilpala's CPDT, Dan Frumin, 10/18/2016
- Re: [Coq-Club] Stumped by a perfectly good looking definition in Chilpala's CPDT, Tej Chajed, 10/18/2016
- Re: [Coq-Club] Stumped by a perfectly good looking definition in Chilpala's CPDT, Satrajit Roy, 10/18/2016
- Re: [Coq-Club] Stumped by a perfectly good looking definition in Chilpala's CPDT, Tej Chajed, 10/18/2016
- Re: [Coq-Club] Stumped by a perfectly good looking definition in Chilpala's CPDT, Satrajit Roy, 10/18/2016
- Re: [Coq-Club] Stumped by a perfectly good looking definition in Chilpala's CPDT, Satrajit Roy, 10/19/2016
- Re: [Coq-Club] Stumped by a perfectly good looking definition in Chilpala's CPDT, Hugo Herbelin, 10/20/2016
- Re: [Coq-Club] Stumped by a perfectly good looking definition in Chilpala's CPDT, Tej Chajed, 10/18/2016
- Re: [Coq-Club] Stumped by a perfectly good looking definition in Chilpala's CPDT, Satrajit Roy, 10/18/2016
- Re: [Coq-Club] Stumped by a perfectly good looking definition in Chilpala's CPDT, Satrajit Roy, 10/18/2016
- Re: [Coq-Club] Stumped by a perfectly good looking definition in Chilpala's CPDT, Satrajit Roy, 10/17/2016
- Re: [Coq-Club] Stumped by a perfectly good looking definition in Chilpala's CPDT, John Wiegley, 10/17/2016
Archive powered by MHonArc 2.6.18.