unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Stefan Israelsson Tampe <stefan.itampe@gmail.com>
To: Ian Grant <ian.a.n.grant@googlemail.com>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: implementation idea for infinite cons lists aka scon(e)s lists.
Date: Sat, 13 Sep 2014 13:13:09 +0200	[thread overview]
Message-ID: <CAGua6m1WmqCE0+gE8HvWR0PWfKr+yOdJr3HfWa9t8Sq=gABRMw@mail.gmail.com> (raw)
In-Reply-To: <CAKFjmdx2NyEEBh7JyWvM=kD=votFZn_ejY8_p=G0igr+P1jq8g@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3836 bytes --]

Hi,

The idea is to mod the gc and take advantage of that to trace if the
datastructure ( a cons cell) so that one can now that
it is saved from gc by havinga special reference and that we also can see
if the cons cell have been referenced outside of the
special references. Then in the sweep phase one can decide to modify the
cons list to set the cdr to null in say 1000 cons from the
head. But this modding is only done if there is now referncing of it
outside the special references. This means that the rest of the tail
will gc normally and be reclaimed. If however a function wants to analyze a
part of the list it just references the head and by that the gc
will not mod any part of the rest of the list and the algorithm can safely
do it's work. It's in the gc's sweep phase that the list is cut with a
setcdr!

/Stefan

On Fri, Sep 12, 2014 at 10:08 PM, Ian Grant <ian.a.n.grant@googlemail.com>
wrote:

> > #|
> > 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
>
>

[-- Attachment #2: Type: text/html, Size: 4629 bytes --]

  parent reply	other threads:[~2014-09-13 11:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-12 20:08 implementation idea for infinite cons lists aka scon(e)s lists Ian Grant
2014-09-13  1:22 ` Ian Grant
2014-09-13 11:19   ` Stefan Israelsson Tampe
2014-09-15 14:37     ` Ian Grant
2014-09-13 11:13 ` Stefan Israelsson Tampe [this message]
2014-09-15 18:38   ` Ian Grant
  -- strict thread matches above, loose matches on Subject: below --
2014-09-10 20:10 Stefan Israelsson Tampe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAGua6m1WmqCE0+gE8HvWR0PWfKr+yOdJr3HfWa9t8Sq=gABRMw@mail.gmail.com' \
    --to=stefan.itampe@gmail.com \
    --cc=guile-devel@gnu.org \
    --cc=ian.a.n.grant@googlemail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).