Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Co-inductive Streams vs. Functions

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Co-inductive Streams vs. Functions


Chronological Thread 
  • From: Daniel Schepler <dschepler AT gmail.com>
  • To: Coq Club <coq-club AT inria.fr>
  • Subject: Re: [Coq-Club] Co-inductive Streams vs. Functions
  • Date: Thu, 10 Dec 2015 09:12:04 -0800
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=dschepler AT gmail.com; spf=Pass smtp.mailfrom=dschepler AT gmail.com; spf=None smtp.helo=postmaster AT mail-wm0-f51.google.com
  • Ironport-phdr: 9a23:BLheIBPNf2Z+somlDgUl6mtUPXoX/o7sNwtQ0KIMzox0KPv6rarrMEGX3/hxlliBBdydsKIazbOJ+PG7EUU7or+/81k6OKRWUBEEjchE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i760zceF13FOBZvIaytQ8iJ35rxjr/5qsabSj4LrQT+SIs6FA+xowTVu5teqqpZAYF19CH0pGBVcf9d32JiKAHbtR/94sCt4MwrqHwI6LoJvvRNWqTifqk+UacQTHF/azh0t4XXskzoShLHzX8BWC1CmR1RRgPB8RvSX5HrsyK8uPAriweAOsijYbkyWDmmp5xgSBLwjCodf2o162rXh9R0gbhzrxeophg5yInRNtLGfMFid7/QKItJDVFKWdxcAmkYWtux

On Thu, Dec 10, 2015 at 8:31 AM, Thorsten Altenkirch <Thorsten.Altenkirch AT nottingham.ac.uk> wrote:
What are the theoretical reasons for not liking conductive types?

I don't know about theoretical reasons.  But practically, Coq's cofixpoint termination checker can be very limiting.  For example, the natural representation of a possibly non-terminating calculation would look like:

CoInductive calc (X:Type) : Type :=
| result : X
| step : calc X -> calc X.

This is naturally a monad with return := result and

CoFixpoint calc_bind {X:Type} (x:calc X) {Y:Type} (f:X->calc Y) : calc Y :=
match x with
| step x' => step (calc_bind x' f)
| result x0 => f x0
end.

For convenience:

Definition tick : calc unit :=
step (result tt).

(* Auger Cedric style notations *)
Notation "'do' x0 <- x ; y" := calc_bind x (fun x0 => y)
  (at level ?, right associativity, x0 ident).
Notation "'do' x >> y" := calc_bind x (fun _ => y)
  (at level ?, right associativity).

So far so good.  But now, try to represent the naive Fibonacci function as a naive user who doesn't know it will actually terminate:

CoFixpoint fib (n:nat) : calc nat :=
match n with
| 0 => result 0
| 1 => result 1
| S (S m) =>
  do Fm <- fib m;
  do tick >>
  do Fsm <- fib (S m);
  do tick >>
  result (Fm + Fsm)
end.

Coq won't accept this because of the occurrence of fib in the notation-produced function bodies (and I understand there are good reasons for rejecting such definitions).  In fact, I'm convinced that to produce a version that will be accepted, you'll essentially have to encode a runtime stack for the execution yourself - which isn't what you would have "signed up for" starting the exercise.

This example is due to Adam Chlipala.
-- 
Daniel Schepler



Archive powered by MHonArc 2.6.18.

Top of Page