Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Mutual Fixpoints into mutual inductive types

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Mutual Fixpoints into mutual inductive types


Chronological Thread 
  • From: Joachim Breitner <mail AT joachim-breitner.de>
  • To: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] Mutual Fixpoints into mutual inductive types
  • Date: Mon, 08 Jan 2018 19:49:36 +0100
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=mail AT joachim-breitner.de; spf=Neutral smtp.mailfrom=mail AT joachim-breitner.de; spf=None smtp.helo=postmaster AT hermes.serverama.de
  • Ironport-phdr: 9a23:dI+rVBIgh/Njp6be+tmcpTZWNBhigK39O0sv0rFitYgRI/vxwZ3uMQTl6Ol3ixeRBMOHs6sC07KempujcFRI2YyGvnEGfc4EfD4+ouJSoTYdBtWYA1bwNv/gYn9yNs1DUFh44yPzahANS47xaFLIv3K98yMZFAnhOgppPOT1HZPZg9iq2+yo9JDffxhEiCChbb9uMR67sRjfus4KjIV4N60/0AHJonxGe+RXwWNnO1eelAvi68mz4ZBu7T1et+ou+MBcX6r6eb84TaFDAzQ9L281/szrugLdQgaJ+3ART38ZkhtMAwjC8RH6QpL8uTb0u+ZhxCWXO9D9QLYpUjqg8qhrUgflhiQaOTA57m/ZhM5/jKxHrxymqBNy2IHUbJ2POfdkZK7RYdcXSGxcVchRTSxBBYa8YpMLAeoGJ+lXs4n9p1oLrRCjGASsHv3gyj5Uhn/ww6I6yfkqHAbD3AM6HtIOtG/ZrNfyNKgITe+1zKjIzTDaY/xNwzfy9onIcgwnof6SR7J8a9fexlc2Gg7Dk16ep4vlPzaP2eQMtWiW9+hgVeW1hGE7qwFxoz2vyt43hYnTmI0Vy0zE9SNnz4YvP9G3VVB0bcarEJtRqyGaN5Z2Tdg4T250vyY6z7sLsoO4cigS0Jkr2hzSZv2df4WM+B7vSvudLDliiH54dr+yiRC/+lW6xOLmTMm7ylNKozJFktbSsnAN0ATe6siZRftn+0euxy2P2xrI6u5aO0A0i7TUK4Q7zb41jJUfq1nMETHulEX3iq+ZaFkk9/C15+nlY7jqvJuRO5Vqhg3jPKkigNGzDOo2PwQWWmiU4+W81Lnt/U3jR7VKi+U7kqzDv5DbIcQWvay5AwhP3Yk/6xa/DjKm3M0DknkdMl1FeQ6Hj473NFHUOvz3EOmwj0y2kDh33/DGIqHhApLVI3ffl7fhZK9x5FJYyAou1t9S/IlUC7EEIPLrQED9rt3YDhkjMwy12enrEtt91plNEV6IV6SeKebZtUKCzuMpOeiFIoEP6xjnLP1wxfnnhn84nBc3Z6SowZ0acjjsG/1nJ22bZnPngtYEVG0QswsiSuHwzlGPB20AL02uVr4xs2loQLmtCp3OE9ig

Hi,

ok, I found the problem. See
https://gist.github.com/nomeata/1c2bae07c4f4943fc9f9cd64801d9ad4

The CPS-trick helps only if you _never ever_ have a global definition
of a dictionary record. Instead, dictionary records must only occur as
arguments to continuations. So don't write

Definition vPure : @Pure__Dict (fun t => Vector.t t 1) :=
{| pure__ _ x := [x] |}.
Global Instance vector_Pure : @Pure (fun t => Vector.t t 1) :=
fun r f => f vPure.

but write

Global Instance vector_Pure : @Pure (fun t => Vector.t t 1) :=
fun r f => f {| pure__ := fun _ x => [x] |}.

Then your definitions go through!

Joachim

Am Montag, den 08.01.2018, 18:25 +0000 schrieb Merlin Göttlinger:
> Hi,
>
> sorry for the confusion:
> https://gist.github.com/mgttlinger/cede4fd8fe96aa7f7996341f878a8eb5
> That should be a self contained file that exhibits the desired and the
> working implementation.
> The version with traverse being implemented on instance creation is also in
> there as traverse'.
>
> Cheers,
> Merlin
>
>
> Joachim Breitner
> <mail AT joachim-breitner.de>
> schrieb am Mo., 8. Jan. 2018 um 16:25 Uhr:
> > Hi,
> >
> > I am a bit lost. Can you share a complete minimal working example of
> > the Coq code that you hoped to work, and also the variant that you
> > wrote that actually work?
> >
> > Cheers,
> > Joachim
> >
> > Am Montag, den 08.01.2018, 10:53 +0000 schrieb Merlin Göttlinger:
> > > Hi,
> > >
> > > Joachim Breitner
> > > <mail AT joachim-breitner.de>
> > > schrieb am Mo., 8. Jan. 2018 um 11:04 Uhr:
> > > > Hi,
> > > >
> > > >
> > > > Am Montag, den 08.01.2018, 08:23 +0000 schrieb Merlin Göttlinger:
> > > > > sure. My guess would be that I messed up the encoding of the
> > > > > hierarchy and the fmap call in the implementation of traverse is
> > > > > therefore not resolved to be be the Vector.map call.
> > > > > https://gist.github.com/mgttlinger/db35a3748f1dfe68c152678f9a714c06
> > > >
> > > > ah, you are using features I have not played around with (e.g. :>, and
> > > > default definitions in a record).
> > >
> > > I just tried implementing traverse like this:
> > >
> > > Definition traverse `{T: Traversable} `{@Applicative G} {t u} : (t ->
> > > G u) -> F t -> G (F u) :=
> > > let f := T _ (t_f__) in fun f ft => sequence (fmap f ft).
> > >
> > > As to not rely on the default implementation in the record. That didn't
> > > change anything.
> > > Implementing traverse at the instance creation also didn't help.
> > > I suspect it could be because my implementation is defined
> > > interactively.
> > >
> > > Definition vSequence {G} {n} `{Applicative G} : forall T, Vector.t (G
> > > T) n -> G (Vector.t T n).
> > > intros. induction X; pose proof _f as f; pose proof _p as p. apply
> > > pure; trivial. apply (@point (fun f => Vector.t f 0) _ _). eapply ap.
> > > apply (fmap (fun a b => a :: b) h). exact IHX.
> > > Defined.
> > >
> > > This is the definition. The Instance is then essentially
> > >
> > > Definition vTraversable {G} {n} : @Traversable__Dict (fun t => Vector.t
> > > t n) G := {| sequence__ _ := vSequence;
> > > |}.
> > > Global Instance vector_Traversable {n} {G} : @Traversable (fun t =>
> > > Vector.t t n) G := fun r f => f vTraversable.
> > >
> > > > Does it work if you do not give the definition of traverse__ in the
> > > > Record definition, and instead give it during your Instance? Where is
> > > > your Instance?
> > > >
> > > > > What is the "local go" pattern? A quick google lead me only to
> > > > > things
> > > > > related to Go-lang.
> > > >
> > > > There might be a better name. It is the problem that nested recursion
> > > > through map defined like
> > > >
> > > > Fixpoint map f xs := match xs with
> > > > | [] => []
> > > > | x :: ys => f x :: map f ys end.
> > > >
> > > > fails but
> > > >
> > > > Definition map f :=
> > > > fix go xs := match xs with
> > > > | [] => []
> > > >
> > > > | x :: ys => f x :: go ys end.
> > > >
> > > > works.
> > >
> > > Good to know.
> > >
> > > Cheers,
> > > Merlin
> > --
> > Joachim Breitner
> >
> > mail AT joachim-breitner.de
> > http://www.joachim-breitner.de/
--
Joachim Breitner

mail AT joachim-breitner.de
http://www.joachim-breitner.de/

Attachment: signature.asc
Description: This is a digitally signed message part




Archive powered by MHonArc 2.6.18.

Top of Page