Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Typeclass confusions

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Typeclass confusions


Chronological Thread 
  • From: Abhishek Anand <abhishek.anand.iitg AT gmail.com>
  • To: coq-club <coq-club AT inria.fr>
  • Subject: Re: [Coq-Club] Typeclass confusions
  • Date: Sat, 24 Jun 2017 08:30:24 -0400
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=abhishek.anand.iitg AT gmail.com; spf=Pass smtp.mailfrom=abhishek.anand.iitg AT gmail.com; spf=None smtp.helo=postmaster AT mail-vk0-f41.google.com
  • Ironport-phdr: 9a23:mGDzGRIBqfKbqbg3S9mcpTZWNBhigK39O0sv0rFitYgRI//xwZ3uMQTl6Ol3ixeRBMOAuq0C07KempujcFRI2YyGvnEGfc4EfD4+ouJSoTYdBtWYA1bwNv/gYn9yNs1DUFh44yPzahANS47xaFLIv3K98yMZFAnhOgppPOT1HZPZg9iq2+yo9ZDeZwdFiCChbb9uMR67sRjfus4KjIV4N60/0AHJonxGe+RXwWNnO1eelAvi68mz4ZBu7T1et+ou+MBcX6r6eb84TaFDAzQ9L281/szrugLdQgaJ+3ART38ZkhtMAwjC8RH6QpL8uTb0u+ZhxCWXO9D9QLYpUjqg8qhrUgflhyUJNzA5/m/ZidF+grxHrx+6vRNz35TZbZuJOPZifK7Qe84RS2pbXsZWUixMGp+xYJAPD+oAJuZYr5fyp1gTphaiAwmjHuXvxSJVjXLxx6I1yOQhEQDd3AwgAd0Os27Yo8/zNKgIV+C60bPEzTTCb/NK1jfw84fIchU7rvGNWbJ8a9beyU4qFw7ciFibtILrPzSQ1usXsmib6fJtWv6oi249rQF+vDyvxsM2hobXm40V11bJ/jh6zoYtPdC0VlJ3bNq+HJZTtyyWLZV6Tt4sTm1ytys217sLsoOhcicQ0pQo3RvfZuSHc4eW5hLjU/6cITJii3JkfLKzngiy8Uu8xuHlWMm530tGojBKktnLsXAN2BjT5dadRvRh+Ueh3C6D1wHV6u5aPUA5jbTXJ4Ilz7IqlZcesV7PEjHrlEj4lqObeVgo9vCt6+v9Y7XmopGcN5VzigH7KqkhgNewAeQ5MggVX2iU5+e82Kf58k3/WrpKiOA5nrPYsJDbOcQbqbW0AwBQ0ok56ha/Cy2q38gfnXkCNF5FYg6Ij5D1O1HSJ/D1Feuwg1O1kDty2//GOqDhDY7WI3jYkLbheK595FRGxAoyy9Bf/ZNUBasbLPL9QE+i/ODfWxQ+Kkm/x/vtQIF20ZpbUmaSCIeYNrnTuBmG/LR8DfOLYdo8sjb8MPgo5LbHi3Y/lRdJdKOp3IAXZXP+F/JvJUnfYHvwjf8OFG4Lukw1S+m82w7KaiJae3vnB/F03To8Eo/zVYo=

I've had trouble with instance/record notations in other contexts as well. 
Perhaps the tutorial should emphasize that one can always fall back to the basics and use the underlying constructor for the Inductive (typeclasses are just records, which are just Inductives):

(* fails with the same error: *)
Instance eqdecBool : EqDec bool := 
Build_EqDec _ _ Bool.eqb_prop.

(* succeeds: *)
Instance eqdecBool : EqDec bool := 
Build_EqDec bool _ Bool.eqb_prop.




On Fri, Jun 23, 2017 at 7:08 PM, Benjamin C. Pierce <bcpierce AT cis.upenn.edu> wrote:
Many thanks for all the helpful responses to my query about typeclasses the other day.  I’m working on incorporating them into the tutorial I’m writing.  In the process, I’m generating fresh confusions. :-)

Can someone explain the following?  

Thanks!

   - Benjamin

Require Arith.
Require Bool.

Class Eq A :=
  {
    eqb: A -> A -> bool;
  }.

Instance eqBool : Eq bool :=
  {|
    eqb := fun (b c : bool) => 
       match b, c with
         | true, true => true
         | true, false => false
         | false, true => false
         | false, false => true
       end
  |}.

(* UNCOMMENTING THIS MAKES THE DECLARATION of eqdecBool FAIL (why??)...
Instance eqNat : Eq nat :=
  {|
    eqb := Arith.EqNat.beq_nat
  |}.
*)

Class EqDec (A : Type) {H : Eq A} := 
  { 
    eqb_leibniz : forall x y, eqb x y = true -> x = y 
  }.

(* ... BUT REMOVING THE |'s MAKES IT SUCCEED AGAIN (why??) *)
Instance eqdecBool : EqDec bool := 
  {|
    eqb_leibniz := Bool.eqb_prop
  |}.





Archive powered by MHonArc 2.6.18.

Top of Page