From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ian Grant Newsgroups: gmane.lisp.guile.devel Subject: implementation idea for infinite cons lists aka scon(e)s lists. Date: Fri, 12 Sep 2014 16:08:34 -0400 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=089e0117643d8a759a0502e3d952 X-Trace: ger.gmane.org 1410552535 8391 80.91.229.3 (12 Sep 2014 20:08:55 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 12 Sep 2014 20:08:55 +0000 (UTC) To: stefan.itampe@gmail.com, guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri Sep 12 22:08:50 2014 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XSX9E-00035N-Ns for guile-devel@m.gmane.org; Fri, 12 Sep 2014 22:08:48 +0200 Original-Received: from localhost ([::1]:47174 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XSX9E-0001kL-A4 for guile-devel@m.gmane.org; Fri, 12 Sep 2014 16:08:48 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60393) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XSX98-0001k8-QY for guile-devel@gnu.org; Fri, 12 Sep 2014 16:08:44 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XSX91-0006vZ-TC for guile-devel@gnu.org; Fri, 12 Sep 2014 16:08:37 -0400 Original-Received: from mail-wi0-x236.google.com ([2a00:1450:400c:c05::236]:34314) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XSX91-0006vN-Hc for guile-devel@gnu.org; Fri, 12 Sep 2014 16:08:35 -0400 Original-Received: by mail-wi0-f182.google.com with SMTP id e4so1281971wiv.15 for ; Fri, 12 Sep 2014 13:08:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=doT9KBdwuDel8sK+eHr3zBwTdG7t/5lGJzJ8NodRP7s=; b=ubVFigqAuFCCDk+RLsHZi5jYt/1dQFnHUrPbNmBVkWgKF3Vx8q9gMUma48WBYQZn2+ nBkj97Y5OZX2SZMu8e8bhWEpF3VWqE5xbqUuy0+wBlIiKZn4ou6XFVJaao7lfpWA3W9L kk69n1QeAZCPajE7SszcEtvFyQlxb/nNtQ4e/KiZ+IzZ7of73Y6ztIwKA0wabVAL7+Wj iEyPn7T7u37Rmn916JuNAEWQ2YWbXy+JlrJr5Cj/WIgOb9fEPvq63sVDXy2Ro88gDCw5 wYWvqZw4av8DUaa5I22SOvEMh9Ysj1uX3b9jXYbu6I9+uniK45cdxjKBchEndeKDt1GW KT8w== X-Received: by 10.194.122.6 with SMTP id lo6mr13994313wjb.17.1410552514112; Fri, 12 Sep 2014 13:08:34 -0700 (PDT) Original-Received: by 10.194.43.69 with HTTP; Fri, 12 Sep 2014 13:08:34 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::236 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:17441 Archived-At: --089e0117643d8a759a0502e3d952 Content-Type: text/plain; charset=UTF-8 > #| > Basically a stream is > [x,y,z,...] > But we want to gc the tail of the stream if not reachable. How to do this? I don't understand. The tail is infinitely long. When do you want to GC it? When your infinite memory is 50% full, or 75% full :-) I think you probably have a good idea, but it's just not at all clear from these two messages. Do you know about co-induction and co-data? An ordinary (proper) list is an example of an inductive structure: you have two constructors, a nullary one '() which is like a constant or a constant function, it takes no arguments and makes a list out of nothing. And you have a binary constructor, cons, which takes a head a tail as arguments and makes a new list. And then you can use these a bit like an induction proof in mathematics: '() is the base case, and cons is the induction step which takes you from a list, to a new longer list. This is a concrete datatype: the elements it is made of are all represented in memory. The dual of this idea is a co-datatype like a stream, where you don't have the concrete data structures anymore, you have what is called an _abstract datatype_ which is a datatype that has no actual representation in the machine: so you don't have the constructors '() and cons anymore, you just have a single deconstructor, snoc, which, when it is applied to a stream, maybe returns an element and a new stream, which is the tail, otherwise it just returns something like #f which says "it ended!" In languages like scheme and standard ML which do eager evaluation, streams are modelled using either references (i.e. mutable cons cells) or eta-expansions (thunks, (lambda () ...) with a 'unit' argument to delay evaluation), but in lazy languages like haskell (and untyped lambda calculus under normal order evaluation) you don't need any tricks, you can just write the co-data types as ordinary lambda expressions, and the 'call by name' semantics mean that these 'infinite tails' only get expanded (i.e. represented in the memory) when they are 'observed' by applying the deconstructor. So like in real life, the only garbage you have to deal with is the stuff that results from what you make: the whole infinite substructure is all 'enfolded' underneath and takes no space at all. It's just your observing it that makes it concrete. There is a huge body of theory and an awful lot of scribbling been done about this. There are mathematical texts where it's called 'category theory' or 'non well-founded set theory' And it comes up in order theory as 'fixedpoint calculus' and the theory of Galois connections. And in other areas of computer science it's called bisimulation. To me it all seems to be the same thing: "consing up one list while cdr'ing down another", but there's probably no research mileage in saying things like that. Ian --089e0117643d8a759a0502e3d952 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
> #|
> Basically a stream is
> [x,y,z,...]

> But we want to gc the tail= of the stream if not reachable. How to do this?

I= don't understand. The tail is infinitely long. When do you want to GC = it? When your infinite memory is 50% full, or 75% full :-)

I think you probably have a good idea, but it's just not at all clear= from these two messages.

Do you know about co-induction = and co-data? An ordinary (proper) list is an example of an inductive struct= ure: you have two constructors, a nullary one '() which is like a const= ant or a constant function, it takes no arguments and makes a list out of n= othing. And you have a binary constructor, cons, which takes a head a tail = as arguments and makes a new list. And then you can use these a bit like an= induction proof in mathematics: '() is the base case, and cons is the = induction step which takes you from a list, to a new longer list. This is a= concrete datatype: the elements it is made of are all represented in memor= y.

The dual of this idea is a co-datatype like a stream, = where you don't have the concrete data structures anymore, you have wha= t is called an _abstract datatype_ which is a datatype that has no actual r= epresentation in the machine: so you don't have the constructors '(= ) and cons anymore, you just have a single deconstructor, snoc, which, when= it is applied to a stream, maybe returns an element and a new stream, whic= h is the tail, otherwise it just returns something like #f which says "= ;it ended!" In languages like scheme and standard ML which do eager ev= aluation, streams are modelled using either references (i.e. mutable cons c= ells) or eta-expansions (thunks, (lambda () ...) with a 'unit' argu= ment to delay evaluation), but in lazy languages like=C2=A0 haskell (and un= typed lambda calculus under normal order evaluation) you don't need any= tricks, you can just write the co-data types as ordinary lambda expression= s, and the 'call by name' semantics mean that these 'infinite t= ails' only get expanded (i.e. represented in the memory) when they are = 'observed' by applying the deconstructor. So like in real life, the= only garbage you have to deal with is the stuff that results from what you= make: the whole infinite substructure is all 'enfolded' underneath= and takes no space at all. It's just your observing it that makes it c= oncrete.

There is a huge body of theory and an awful lot = of scribbling been done about this. There are mathematical texts where it&#= 39;s called 'category theory' or 'non well-founded set theory&#= 39; And it comes up in order theory as 'fixedpoint calculus' and th= e theory of Galois connections. And in other areas of computer science it&#= 39;s called bisimulation. To me it all seems to be the same thing: "co= nsing up one list while cdr'ing down another", but there's pro= bably no research mileage in saying things like that.

Ian

--089e0117643d8a759a0502e3d952--