From: Alex Baretta <alex@baretta.com>
To: Keith Wansbrough <Keith.Wansbrough@cl.cam.ac.uk>
Cc: Luca Pascali <pasckosky2000@yahoo.it>, caml-list@inria.fr
Subject: Re: [Caml-list] Recursive lists
Date: Fri, 08 Oct 2004 16:42:44 +0200 [thread overview]
Message-ID: <4166A764.3010905@baretta.com> (raw)
In-Reply-To: <E1CFuqr-0000uk-00@mta1.cl.cam.ac.uk>
Keith Wansbrough wrote:
>
> How could they do this? It's just a list; there's nothing special
> about it, except that it has no end.
Lists can be recursive. This means that the list type models a set of
values which includes the cyclic lists. The ocaml type system allow both
for such values and for functions manipulating them, so it's perfectly
natural to expect the List module to treat cyclic lists correctly.
Besides, the cyclicity of a list is a perfectly decidable property by
virtue of the pumping lemma.
> You might be able to do it by keeping a list of all the nodes you've
> visited, and using physical equality to check if you have already
> visited a node.
Good point; however, we must keep a list of tails of visited nodes.
Physical equality of nodes is a necessary but insufficient condition for
recursiveness. On the other hand, if two nodes of the list have the same
tail, then we have proven that the list is cyclic.
> But it would be better to design a more appropriate
> data structure for your application, one for which such tricks are not
> needed.
There is no more appropriate data structure than a cyclic list to model
a possibily infinite (cyclic) sequence of input data. Have you ever seen
type schemas like the following:
# type 'a t = 'a -> 'a t;;
type 'a t = 'a -> 'a t
This is a perfectly sensible use of recursive data structures: there is
no other way to model a type whose expanded representation is infinite.
type 'a t = 'a -> 'a -> 'a -> ...
> What are you trying to do?
We are modelling an optimization problem where a finite number of
requests must be served, as efficiently as possible, from a possibly
infinite set of instances of a finite number of classes of resources.
Each resource class is modelled by a list element. The cyclicity of the
resource list can be used to express no limits on the amount of
resources available. Yet, the optimization program must know better than
simply scan the list sequentially, or unsatisfiable constraint sets
cannot be identified in finite time.
Our algorithm works now, so we do not depend on the availability of
cyclic-list aware standard library. We are simply trying to point out
that the current List module is very naif about infinite lists. I would
like to start a discussion as to whether the List module ought to
correctly handle cyclic lists or not. I argue that since they are
legimitate citizens of the language, the standard library should handle
them correctly. We are willing to contribute our code, so that this
might not weigh on the Caml breeders.
Alex
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
next prev parent reply other threads:[~2004-10-08 14:41 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-10-08 13:20 Luca Pascali
2004-10-08 13:31 ` Keith Wansbrough
2004-10-08 14:32 ` skaller
2004-10-08 14:42 ` Alex Baretta [this message]
2004-10-08 15:43 ` David Brown
2004-10-08 17:19 ` Alex Baretta
2004-10-08 23:29 ` skaller
2004-10-09 8:35 ` Keith Wansbrough
2004-10-09 9:07 ` skaller
2004-10-09 8:32 ` Keith Wansbrough
2004-10-08 17:18 ` Wolfgang Lux
2004-10-11 0:44 ` Brian Hurt
2004-10-11 6:32 ` William Lovas
2004-10-11 6:52 ` Ville-Pertti Keinonen
2004-10-13 11:29 ` Alex Baretta
2004-10-13 11:22 ` Alex Baretta
2004-10-11 9:04 ` Keith Wansbrough
2004-10-08 14:05 ` Sébastien Furic
2004-10-08 14:44 ` Alex Baretta
2004-10-08 15:09 ` Jon Harrop
2004-10-08 15:13 ` james woodyatt
2004-10-08 14:26 ` sejourne_kevin
2004-10-08 18:28 ` Alex Baretta
2004-10-11 8:01 ` Jean-Christophe Filliatre
2004-10-11 9:20 ` Diego Olivier Fernandez Pons
2004-10-11 13:38 ` [Caml-list] About Obj (was Recursive lists) Christophe Raffalli
2004-10-11 13:49 ` [Caml-list] " Christophe Raffalli
2004-10-11 15:33 ` [Caml-list] " Jon Harrop
2004-10-11 16:09 ` Richard Jones
2004-10-11 16:40 ` [Caml-list] About Obj Yamagata Yoriyuki
2004-10-13 11:59 ` Alex Baretta
2004-10-11 16:24 ` [Caml-list] About Obj (was Recursive lists) james woodyatt
2004-10-11 16:46 ` brogoff
2004-10-11 17:24 ` james woodyatt
2004-10-12 0:19 ` skaller
2004-10-20 22:10 ` Greg K
2004-10-12 15:19 ` Christophe Raffalli
2004-10-13 11:42 ` Alex Baretta
2004-10-13 21:19 ` brogoff
2004-10-14 9:52 ` Andreas Rossberg
2004-10-14 17:38 ` brogoff
2004-10-15 8:22 ` Alex Baretta
2004-10-15 17:02 ` brogoff
2004-10-17 13:42 ` Alex Baretta
2004-10-12 6:17 ` [Caml-list] Recursive lists sejourne_kevin
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4166A764.3010905@baretta.com \
--to=alex@baretta.com \
--cc=Keith.Wansbrough@cl.cam.ac.uk \
--cc=caml-list@inria.fr \
--cc=pasckosky2000@yahoo.it \
/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