Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] multiple typeclass instance question

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] multiple typeclass instance question


Chronological Thread 
  • From: Jason Gross <jasongross9 AT gmail.com>
  • To: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] multiple typeclass instance question
  • Date: Thu, 10 Mar 2016 03:11:16 +0000
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=jasongross9 AT gmail.com; spf=Pass smtp.mailfrom=jasongross9 AT gmail.com; spf=None smtp.helo=postmaster AT mail-oi0-f51.google.com
  • Ironport-phdr: 9a23:u/JoZxWw8v+YOw1+OtBWOk4DWoHV8LGtZVwlr6E/grcLSJyIuqrYZheBt8tkgFKBZ4jH8fUM07OQ6PC/HzxfqsvQ+Fk5M7VyFDY9wf0MmAIhBMPXQWbaF9XNKxIAIcJZSVV+9Gu6O0UGUOz3ZlnVv2HgpWVKQka3CwN5K6zPF5LIiIzvjqbpq8KVM1oD2Wv1SIgxBSv1hD2ZjtMRj4pmJ/R54TryiVwMRd5rw3h1L0mYhRf265T41pdi9yNNp6BprJYYAu2pN5g/GLdfFXEtN30/zMztrxjKCwWVtVUGVWBDsBNTBA6Nwwv9RYy55inzre171zOdJtanZb8xUDWmqaxsTUm72288Kzcl/TSP2YRLh6VBrUf5qg==

Axiom A : Type.
Existing Class A.
Axioms a a' : A.
Existing Instances a a'.

Class MultiA (n : nat) {x : A} := dummy : list A.

Hint Extern 0 (@MultiA 0 ?x) => (exact nil) : typeclass_instances.
Hint Extern 0 (@MultiA (S ?n) ?x) => (let prev := constr:(_ : @MultiA n _) in
                                      match eval cbv beta in prev with
                                      | context[cons x _] => fail 1
                                      | ?prev' => exact (cons x prev')
                                      end) : typeclass_instances.
Goal True.
  pose (_ : MultiA 2). (* m := ((a :: a' :: nil)%list : MultiA 2) : MultiA 2 *)

There's probably a way to do this without giving the length of the list ahead of time, but I hope this gives a bit of insight into the model I'm using of typeclass resolution hackery.

On Wed, Mar 9, 2016 at 9:44 PM Jonathan Leivent <jonikelee AT gmail.com> wrote:


On 03/09/2016 09:06 PM, Jason Gross wrote:
>> But, is there a way to have something print both foo_a and foo_b?
> Axiom A : Type.
> Existing Class A.
> Axioms a a' : A.
> Existing Instances a a'.
>
> Class MultiA {x : A} := dummy : True.
>
> Hint Extern 0 (@MultiA ?x) => idtac x; fail : typeclass_instances.
>
> Goal True.
>    try pose (_ : MultiA).
> (* a'
> a
> a'
> a
> a'
> a
> a'
> a *)
>
>
> Not sure why there's so much duplication, but can you make this work?

That's a strange solution.  But, as far as I can tell, it can only
print.  One can't make other use of the non-most-recent instances,
right?  In fact, MultiA has to not have any actual instances for this to
work, it seems.

-- Jonathan




Archive powered by MHonArc 2.6.18.

Top of Page