Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Type error for user-defined induction principle for inductive type

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Type error for user-defined induction principle for inductive type


Chronological Thread 
  • From: Jerome Hugues <jhugues AT andrew.cmu.edu>
  • To: "coq-club AT inria.fr" <coq-club AT inria.fr>
  • Subject: Re: [Coq-Club] Type error for user-defined induction principle for inductive type
  • Date: Sat, 30 Jan 2021 01:53:01 +0000
  • Accept-language: en-US
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=jhugues AT andrew.cmu.edu; spf=Pass smtp.mailfrom=jhugues AT andrew.cmu.edu; spf=None smtp.helo=postmaster AT relay-exchange.andrew.cmu.edu
  • Ironport-phdr: 9a23:jCUbOBW0ZgRXO866LxJ2P0McpLnV8LGtZVwlr6E/grcLSJyIuqrYbRaGt8tkgFKBZ4jH8fUM07OQ7/mxHzdbqs3f+DBaKdoQDkBD0Z1X1yUbQ+e9QXXhK/DrayFoVO9jb3RCu0+BDE5OBczlbEfTqHDhpRQbGxH4KBYnbr+tQt2agMu4zf299IPOaAtUmjW9falyLBKrpgnNq8Uam4RvJrs1xxfTrHZFdetayG1pKFmOmxrw+tq88IRs/ihNuf8t7dJMXbn/c68lUbFWETMqPnwv6sb2rxfDVwyP5nUdUmUSjBVFBhXO4Q/5UJnsrCb0r/Jx1yaGM8L4S7A0Qimi4LxwSBD0kicHNiU2/3/Rh8dtka9UuhOhpxh4w47JfIGYMed1c63Bcd8GQ2dKQ8BcXDFDDIyhdYsCF+oPM/hFoYnhqVUArhW+CgutBOzzxTBFnWX50bE/0+k7DQ3KwA4tEtQTu3rUttX1M6ISXPixwqbW1zXDaPZW1ing44bKbxAhruyMUqxrccHMzkQvFQPFjkifqYz4ITyVzf8AvHKd7+V9T+KglWAmpxttrTiq28cgkJfGiZ8Iyl3d8yhy3Yk6K8GiRkFhfd6kDIVftzucN4ZuTc0vQW9mtSI5x7AbpJK2YScHxYopyhPCZPKJfYeF7BLsWeqPPzt1i31odbG7ihuz8EWt1O7xW9W73ltUsyZInd/BvW0O2RzL8sWLV+Vx80S71TqRzQzf9+FJLEIumabFJJMt2qM8moQQvEjZACP6gkr7gLGMekgr4uSk9vrrb7b8qpOCLYN4lwHzP6Y0lsG8A+k1NBUFUXKB9uSmzrLj+FX0QLVUgf0ylanUqIraKtofpqGjAw5Zy5gs6hmjADemytsYm3YHI0xfdB2diYjmJkvOL+72DPuln1uslSpry+rYMbL8H5XBNnnDkLH/crZh80NQ1RQ/wNNF655KEL0NPfL+V03ruNDGARI1Kwm0zPzmCNV52IMeQ2WPAqqBPaPQsV+I++0vI/SSa48OozvyMf4l6OP0jXAnl14RZ7Wm3Z4KaHyiAPtpPliZbWL2gtgdCWcKohY+TOvyhVKeVj5Tfm++UL445jEmE42rFpzDR4CogLyZxii3BJxWZmZcClCNC3jkbYuEW+1fIB6Vd4VqlSVBXry8Qacg0wuvvUn00fAveuHT42gTsY/p/Nlz/eza0x8oo29aFcOYhkOAVWZxkysoWjAr0bs39U5911ie3LNQivpUD9FMofhMT0E3OYOKnL8yMMz7Rg+UJoTBc12hWNjzWWhtHOJ0+McHZgNGI/vnlgrKhnT4CrkZjbGUQpcx7+TR02Wjf58gmUaD77EoihwdeuUKNWCigfUmpRLeA4fY1kiJnKajc6sRmifL+H2O0iyFuVweXQJtA/2cDCIvI3DOpNG83XvsCrqnCLApKAxEkJDQI61GcND2y15DWbHuNMmMOm8=

Thanks Jason,

 

You pointed to the right direction. Obviously the type checker was confused and I now understand how to interpret it.

 

For the record, here is the final working solution

 

(*************)

 

From Coq Require Import List.

 

Set Implicit Arguments.

Set Asymmetric Patterns.

 

Inductive componentInstance :=

    | component_instance : nat -> list subcomponentInstance -> componentInstance

with subcomponentInstance :=

    | subcomponent_instance : nat -> componentInstance -> subcomponentInstance.

 

Section All.

 

    Variable T : Set.

    Variable P : T -> Prop.

 

    Fixpoint All (ls : list T) : Prop :=

      match ls with

        | nil => True

        | h :: t => P h /\ All t

      end.

 

  End All.

 

Section componentInstance_ind'.

 

  Variable Pc : componentInstance -> Prop.

 

  Definition Ps (s : subcomponentInstance) : Prop :=

    match s with

    | subcomponent_instance _ c => Pc c

    end.

 

  Variable Pls : list subcomponentInstance -> Prop.

 

  Hypothesis component_case : forall (n : nat) (ls : list subcomponentInstance),

    All Ps ls -> Pc (component_instance n ls).

 

Fixpoint componentInstance_ind' (c : componentInstance) : Pc c :=

  match c return Pc c with

  | component_instance n ls =>

    component_case n ls

    ((fix subcomponentInstance_ind (ls : list subcomponentInstance) : All (Ps) (ls) :=

      match ls return All _ ls  with

      | nil => I

      | subcomponent_instance _ c' :: ls' =>

          conj (componentInstance_ind' c')

               (subcomponentInstance_ind ls')

      end)

    ls)

end.

 

End componentInstance_ind'.

 

From: <coq-club-request AT inria.fr> on behalf of Jason Gross <jasongross9 AT gmail.com>
Reply-To: "coq-club AT inria.fr" <coq-club AT inria.fr>
Date: Friday, January 29, 2021 at 7:57 PM
To: coq-club <coq-club AT inria.fr>
Subject: Re: [Coq-Club] Type error for user-defined induction principle for inductive type

 

Have not tried running the code, but try `match ls return All _ ls with` instead of `match ls with`.  The error message that you got is saying "I don't know how to figure out what to apply "All" to to get "True"".  Another way of phrasing this issue is that when you write "match ls with ..." it doesn't know whether you want the type of the branches to be in terms of `ls`, or to be in terms of the branch of the match.


Best,

Jason

 

 

On Fri, Jan 29, 2021 at 5:22 PM Jerome Hugues <jhugues AT andrew.cmu.edu> wrote:

Thanks for the suggestion

I tried this, but this still produces the same error on nil => I (see rewrite below)
The error changed to

The term "I" has type "True" while it is expected to have type
"All Ps ?l@{ls:=ls0; l0:=nil}".

which is a similar error message with different variable names due to the renaming

Fixpoint componentInstance_ind' (c : componentInstance) : Pc c :=
  match c with
  | component_instance n ls =>
    component_case n ls
    ((fix subcomponentInstance_ind (ls : list subcomponentInstance) : All (Ps) (ls) :=
      match ls with
      | nil => I (* True *) (* All Ps nil *)
      | subcomponent_instance _ c' :: ls' => (componentInstance_ind' c') /\
          (subcomponentInstance_ind ls')
      end)
    ls)
end.

On 1/29/21, 5:14 PM, "coq-club-request AT inria.fr on behalf of Gaëtan Gilbert" <coq-club-request AT inria.fr on behalf of gaetan.gilbert AT skyskimmer.net> wrote:

    Didn't check but I think

         ((fix subcomponentInstance_ind (lsi : list subcomponentInstance) : All (Ps) (ls) :=

    should be ... : All Ps lsi, not ... : All Ps ls

    Then I would just shadow ls to reduce typo possibilities

    Gaëtan Gilbert

    On 29/01/2021 22:58, Jerome Hugues wrote:
    >      ((fix subcomponentInstance_ind (lsi : list subcomponentInstance) : All (Ps) (ls) :=
    >




Archive powered by MHonArc 2.6.19+.

Top of Page