Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Question about fold and, probably, inductive definitions

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Question about fold and, probably, inductive definitions


Chronological Thread 
  • From: Robbert Krebbers <mailinglists AT robbertkrebbers.nl>
  • To: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] Question about fold and, probably, inductive definitions
  • Date: Mon, 1 Feb 2016 12:28:14 +0100
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=mailinglists AT robbertkrebbers.nl; spf=None smtp.mailfrom=mailinglists AT robbertkrebbers.nl; spf=None smtp.helo=postmaster AT smtp1.science.ru.nl
  • Ironport-phdr: 9a23:KTqgzhMhwJ4M1Fp2M8gl6mtUPXoX/o7sNwtQ0KIMzox0KPn6rarrMEGX3/hxlliBBdydsKIbzbOO+Pq8EUU7or+/81k6OKRWUBEEjchE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i760zceF13FOBZvIaytQ8iJ35vxjrj5ocGbSj4LrQT+SIs6FA+xowTVu5teqqpZAYF19CH0pGBVcf9d32JiKAHbtR/94sCt4MwrqHwI6Lpyv/JHBK79ZuEzSaFSJDUgKWE8osPx5jfZSg7a3HwWWGgMjlJrGQXP5hzgRd+ltyL7sut71y2bJtHtZaozUz6v9btoUhLigiodLHg/9DeE2YRLkKtHrUf59FREyInObdTNOQ==

On 02/01/2016 12:16 PM, Ilmārs Cīrulis wrote:
Fixpoint fold_right A B n (f: B → A → A) (a: A) (L: list B n): A :=
match L with
| nil _ => a
| cons x t => f x (fold_right f a t)
end.
You have to write this function in a slightly different way so as to convince Coq that f remains constant during each recursive call:

Definition fold_right A B (f: B → A → A) :
forall n, A -> list B n -> A :=
fix go n a L :=
match L with
| nil _ => a
| cons x t => f x (go _ a t)
end.

Now f is no longer an argument of the fix.

List.fold_right is written in this way too.



Archive powered by MHonArc 2.6.18.

Top of Page