Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] records ?

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] records ?


Chronological Thread 
  • From: Madhukar <madhukar.yerraguntla AT gmail.com>
  • To: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] records ?
  • Date: Mon, 6 Sep 2021 10:28:10 +0530
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=madhukar.yerraguntla AT gmail.com; spf=Pass smtp.mailfrom=madhukar.yerraguntla AT gmail.com; spf=None smtp.helo=postmaster AT mail-lf1-f41.google.com
  • Ironport-hdrordr: A9a23:JxxRtKGm3EGnrjU/pLqE6ceALOsnbusQ8zAXPo5KOHhom6uj5rmTdZUgpHnJYVMqMk3I9urgBEDtewK+yXcX2/h3AV7BZmfbUQKTRekIgOffKlvbak/DH8FmupuIGJIfNDSfNykesfrH
  • Ironport-phdr: A9a23:VoO7nBUeprWpopIKhvY2nKOJ7WjV8Kw5VTF92vMcY1JmTK2v8tzYMVDF4r011RmVB92duqsP1rWempujcFRI2YyGvnEGfc4EfD4+ouJSoTYdBtWYA1bwNv/gYn9yNs1DUFh44yPzahANS47xaFLIv3K98yMZFAnhOgppPOT1HZPZg9iq2+yo9JDffRlEiCC5bL9vIxm7rQfcvdQKjIV/Lao81gHHqWZSdeRMwmNoK1OTnxLi6cq14ZVu7Sdete8/+sBZSan1cLg2QrJeDDQ9LmA6/9brugXZTQuO/XQTTGMbmQdVDgff7RH6WpDxsjbmtud4xSKXM9H6QawyVD+/6apgVR3mhzodNzMh/27XhM5/gqJVrhyiuhJx3ZLbbZqPO/ZiZK7QZ88WSXZDU8tXSidPApm8b4wKD+cZOuhXtZTyp1sTrRu9HwasHv7kxzhNhnDswKI60/khEQLc0ww6Bd4PsGrbrM/vNKgIXuC10a/IzSnHb/xMwjr9543IfQogofGIR75/bc3RyUw2Gg7Dk16fppDrMSmP2eQRr2iU8fBgVeS3hmI5pQ99vjqiyMgxhoTLgo8Y1kzI+Tl2zosxKtC0VE12bNq4HZZTuCyWKYR4T80jTmxmpCs31L0LtJ6mcSUK1pkqwQPUZfKAc4iN+B3jVeCRLC9lhHJ9Zr2/gRCy/VK+xeLhS8m51ktBoCldktTUqHwByxje5tKER/Z95EutxDeC2gLJ5uxLPEw5k7fQJYQ7zb4qjJUTtFzOHi/ol0Xyi6+bbkAk9fKp6+Tje7nmopGcO5JthgHwPakih9azAes/MggJUGib/fqz2Kf/8k3+RbVGlvw2kq/Hv5DGPckXuLK1DgtP3osg6xuzFSqq3dUakHUdI19JZQqLj43zNFHPJPD4A+2/g1OpkDpzwvDJJKDuApXQLnjAirjhZ6xx6k5Cxwop19BQ/Z1UCqwHIPLvXk/+rsfVDhA8MwOuwubnDM9x2Z8ZWWKKGqOZKr/dsUeU5uIzJOmBfJMauDHkK/Q8+/HuiWI5lkQGcKmy3ZoXbWi4Ee58L0WYZ3rsmNYBHn0QsgowVuy5wGGFBDVUfjO5W782zjA9EoOvS4nZFa63h7nU+S63HoBVb3oOXlWFHXf1dIyeHeYBcjibLdJnjjgNfbekQo4lkxqpsVmpmPJcMuPI93hA5trY399v6riL/fnX3TNxBsWZlWqKSjMs9ovpbzo/3aQ6pUIkj1nfiO53hPtXEdEV7PRMAF9S3XH0wOlzCtS0UQXELI7hdQ==

Hi Jeremy,
As Agnishom mentioned, records are nothing special. If you are familiar with Haskell or ocaml, the record fields can be accessed similarly. For example:


Record
test := mk_test {
name : string;
val : nat}.

Fixpoint test_find (n: string) (xl: list test) : option test :=
match xl with
| [] => None
| x::xs => if (String.eqb (name x) n) then Some x else test_find n xs
end.
(*This uses the haskell-like syntax to refer to name field*)


Fixpoint test_find2 (n: string) (xl: list test) : option test :=
match xl with
| [] => None
| x::xs => if (String.eqb x.(name) n) then Some x else test_find n xs
end.
(* This uses ocaml-like syntax. The peculiarity is the parentheses which are required to parse the statement correctly *)

Lemma test_correct: forall xl n x, test_find n xl = Some x -> x.(name) = n.
Proof.
induction xl; intros; simpl in *.
- inversion H.
- unfold test_find. destruct (name a =? n) eqn:E.
* inversion H; subst x. now apply String.eqb_eq in E.
* now apply IHxl.
Qed.


Thanks,
Madhukar

 


On Mon, Sep 6, 2021 at 9:40 AM Agnishom Chattopadhyay <agnishom AT cmi.ac.in> wrote:
I apologize. Here is a more syntactically correct example.

Inductive Rectangle : Type := {
  height : nat;
  width : nat;
  }.
 
 
Example foo_rect := {| height := 4; width := 5 |}.

Print foo_rect.
Check foo_rect.

Does this help understand what Record types are?

As for your goal, could you give a minimal complete example of the problem you are facing? I could not come up with a natural example myself.



On Sun, Sep 5, 2021 at 10:59 PM Jeremy Dawson <Jeremy.Dawson AT anu.edu.au> wrote:
Hi Agnishom,

I'm rather puzzled - I assume you are saying that the syntax I gave, ie
{| c := ccc ; i := iii |}, is in fact a record.

But if so, why doesn't the split tactic work?

The following you gave:

Definition Person : Type := {
    name : String;
    age : int;
}.

I'm guessing you are saying that defines a record type in Coq.

However why I enter that I get the following error:

Definition Person : Type := {
   name : String;
   age : intCoq < Coq < Coq < }.
Toplevel input, characters 46-47:
 >   name : String;
 >                ^
Error:
Syntax error: '&' or '|' expected after [constr:operconstr level 200]
(in [constr:operconstr]).

Cheers,

Jeremy


On 6/9/21 1:32 pm, Agnishom Chattopadhyay wrote:
> Records are like a product type, with desginated function for each
> projection function. Informally, you can think of them as a class with
> fields in some object oriented language.
>
> For example,
>
> class Person {
>    String name;
>    int age;
> }
>
> would be
>
> Definition Person : Type := {
>    name : String;
>    age : int;
> }.
>
> You can read the section titled "Records are Products" from
> https://softwarefoundations.cis.upenn.edu/qc-current/Typeclasses.html
> <https://softwarefoundations.cis.upenn.edu/qc-current/Typeclasses.html>
> (The rest of the page is not really relevant for this purpose.)
>
> Records are also a feature in OCaml or Haskell. You can google that.
>
>
>
> On Sun, Sep 5, 2021 at 10:20 PM Agnishom Chattopadhyay
> <agnishom AT cmi.ac.in <mailto:agnishom AT cmi.ac.in>> wrote:
>
>     Locate locates notation that is defined by the programmer. I believe
>     that "{|" is syntax which is part of Gallina.
>
>     As for the next step, have you tried split? You can also try solving
>     this with exact.
>
>     --agnishom
>
>     On Sun, Sep 5, 2021, 21:25 Jeremy Dawson <Jeremy.Dawson AT anu.edu.au
>     <mailto:Jeremy.Dawson AT anu.edu.au>> wrote:
>
>
>         Hi,
>
>         I have a hypothesis (got by playing around with someone else's
>         code) of
>         the form {| c := ccc ; i := iii |}
>
>         The command Locate "{|". produces no results.
>
>         I found in the documentation a syntax definition
>
>         term_record::={| field_def*; ;? |}
>
>         but I can't find anything about what that means or what you can
>         do with it.
>
>         Does it mean I have a thing of type ccc and another thing of
>         type iii?
>
>         If so how do I actually get hold of those things?
>
>         Then, when I have a goal of the form {| c := ccc ; i := iii |}
>         what does that mean and what is the next step to solving it?
>
>         Thanks
>
>         Jeremy
>



Archive powered by MHonArc 2.6.19+.

Top of Page