coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Matthieu Sozeau <mattam AT mattam.org>
- To: coq-club AT inria.fr
- Subject: Re: [Coq-Club] Typeclass instance derivation
- Date: Thu, 11 Jan 2018 17:36:03 +0000
- Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=mattam AT mattam.org; spf=Pass smtp.mailfrom=matthieu.sozeau AT gmail.com; spf=None smtp.helo=postmaster AT mail-wm0-f44.google.com
- Ironport-phdr: 9a23:/TQKnBIN3Zd0Uzl9k9mcpTZWNBhigK39O0sv0rFitYgQI/XxwZ3uMQTl6Ol3ixeRBMOHs6sC07KempujcFRI2YyGvnEGfc4EfD4+ouJSoTYdBtWYA1bwNv/gYn9yNs1DUFh44yPzahANS47xaFLIv3K98yMZFAnhOgppPOT1HZPZg9iq2+yo9JDffxhEiCChbb9uMR67sRjfus4KjIV4N60/0AHJonxGe+RXwWNnO1eelAvi68mz4ZBu7T1et+ou+MBcX6r6eb84TaFDAzQ9L281/szrugLdQgaJ+3ART38ZkhtMAwjC8RH6QpL8uTb0u+ZhxCWXO9D9QLYpUjqg8qhrUgflhygJNzE78G/ZhM9+gr9Frh29vBFw2ZLYbZuPOfZiYq/Qf9UXTndBUMZLUCxBB5uxYYwVAOodIeZYr4j9qEUTrRCjGAesA+LuxSFSiX/rwKY31OEhHhva3Aw8Bd0OtW/ZrNDvO6cOTeC61qzIwS/Eb/NM1jfw8Y7FeQ0ir/GURb99c8XcxVMyGw/bjlics4/oMy2P2ukCvGWW6fdrW/i1hG49sQ5xpyCixscyhYnNgYIY0lXE+j94wIYxPNG5Rkt7bcK9HJteuCyXOJF6QswlQ2FvtyY6zqMJtYSncygNzZQr3x/fa/qZfIiU+h/uVumcLS1liH57eL+znRW//Va6xuDzWcS4yFNKoTBEktnIuHANzRvT6s2fR/t45EihxSqP1wDS6u5aPEA4j7HbK5kgw7EujJUTrF/OHiDzmErsja+Wcl8o9fSv6+TiernmvIOTN5doigHiNaQjgtCwAeMhMgQXQ2eb/fm826b48E3iQLRKi+U2nbPDvJDbI8QbvK+5DBVP3oYt8RbsRwuhhd8fhDwMKE9PUBOBlYngfV/Uc97iCvLqpl2wjDdqyu2OBbrzD5zQZizGmav9dLNV7kdA1AM2i9dF6MQHWfk6PPvvVxqp55TjBRgjPlnsmre1OJBGzoobHFm3LOqcOaLWv0WP47t2ceaJbY4R/j36Lqp8vqK8vToCgVYYOJKR894PcnnhRKZjKlmFaH+qhc0OQz9T41gOCdfygVjHagZ9Ina/W6Vmu2M+AYOiSJjGHsWj3ODH0yC8EZlbIGtBDwLUHA==
Hi,
You can probably fix this by giving an explicit (fa : BPL A) type annotation to the binder. Typeclass resolution only considers hypotheses whose type is syntactically a product ending in a applied typeclass, as running arbitrary reductions could slow down resolution significantly. Alternatively, you could write a Hint Extern 1000 => progress hnf in * : typeclass_instances. to do it automatically in every hypothesis, at your own risk :)
Cheers,
— Matthieu
Le jeu. 11 janv. 2018 à 03:41, Merlin Göttlinger <megoettlinger AT gmail.com> a écrit :
Hi,I'm trying to "derive" typeclass instances from existing tpeclass instances by functoriality of the typeclasses.So given a instance (ta : TC A) that is covariant in A and a function (f : A -> B) I would like to write something like (fmap f ta : TC B).Depending on the shape of the typeclass it might also be contravariant or more likely invariant requiring two functions (ab : A -> B) (ba : B ->A).To generalise this I wrote a typeclass Invariant (encoded with the CPS trick discussed recently). Implementing the instances of this has one issue however:Class BPL m := {verum : m;falsum : m;prop : atom -> m;nomi : nom -> m;conj : m -> m -> m;disj : m -> m -> m;}.Global Instance bpl_invar : Invariant (F := BPL) := fun r f => f {| imap__ A B := fun ab ba fa =>{| verum := ab verum; falsum := ab falsum;prop p := ab (prop p);nomi n := ab (nomi n);conj a b := ab (conj (ba a) (ba b));disj a b := ab (disj (ba a) (ba b))|}|}.This leaves me with a wrong type for fa resulting in a missing Instance.A : TypeB : Typeab : A -> Bba : B -> Afa : (fun B : Type => BPL B) A?BPL : "BPL A"if you wrap the inner record creation in let _ : BPL A := fa in ... it works as expected.Why isn't the type of fa reduced without this wrapper?Is there a better way to do what I want to do?Cheers,Merlin
- [Coq-Club] Typeclass instance derivation, Merlin Göttlinger, 01/11/2018
- Re: [Coq-Club] Typeclass instance derivation, Matthieu Sozeau, 01/11/2018
Archive powered by MHonArc 2.6.18.