caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Brian Hurt <bhurt@spnz.org>
To: briand@aracnet.com
Cc: John Prevost <j.prevost@gmail.com>,
	Ocaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] looping recursion
Date: Tue, 27 Jul 2004 22:12:17 -0500 (CDT)	[thread overview]
Message-ID: <Pine.LNX.4.44.0407272201480.6739-100000@localhost.localdomain> (raw)
In-Reply-To: <16647.5177.849829.421587@soggy.deldotd.com>

On Tue, 27 Jul 2004 briand@aracnet.com wrote:

> it really is.
> although I'd actually like it to be an array.
> it's the classic situation, read whole file - iterate on elements.
> easy to do in a list since I don't need to know the size.
> 
> some minor tweaks and I can include the size in a data file and just
> fill an array directly.
> 
> however, my larger point is the fact that the "standard" map blows up
> like that.  as a long time scheme user I just find that plain weird.
> Now Everybody else seems to think I'm weird because I think that's
> weird ;-)
> 
>   Brian> Very long lists are a sign that you're using the wrong data
>   Brian> structure.
> 
> I'm not sure I understand that.  I have 10^6 data points to work on.
> I'm thinking a list or an array is the right data structure.  Although
> an array is more right.  I mean if you are not worried about
> efficiency then incremental transformation by map'ing is a very
> elegant and clean way to go about doing that sort of work.
> 
> Part of the problem is that powerful computers make for lazy
> programmers :-) It's just so easy to read the 10^6 elements into a
> list and then just keep map'ing them to the final value when it only
> takes seconds to do :-) If it took 2 minutes I'd be more inclined to
> think about the problem.
> 

You want an enumeration.  You're basically taking a file, reading it into 
a list, mapping the list multiple different times, and then writting out 
the result, right?  Well, enumerations work the same way.  You take the 
file, and create an enumeration of the lines of the file (there's a 
function that does that).  You then map the enumeration multiple times, 
same map functions.  Then you write out the result.  As a programmer, it 
doesn't change the problem all that much.

But it allows the library to optimize things.  Maps of enumerations are 
applied lazily- that means they aren't calculated until the result is 
needed.  By creating the enumeration of the file doesn't read the file at 
that point.  When you go to write the result out, the output function 
grabs the first line from the enumeration.  This causes the enumeration to 
actually go read the first line of the input file, and apply all the 
appropriate maps to it, before writting it to the output file.  And so on.
You write the code as if the entire data structure were present right now, 
but it works like a stream processor.  With no extra work on the part of 
the programmer.


-- 
"Usenet is like a herd of performing elephants with diarrhea -- massive,
difficult to redirect, awe-inspiring, entertaining, and a source of
mind-boggling amounts of excrement when you least expect it."
                                - Gene Spafford 
Brian


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


  reply	other threads:[~2004-07-28  3:04 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-27 23:43 briand
2004-07-28  0:27 ` John Prevost
2004-07-28  0:38   ` John Prevost
2004-07-28  1:17     ` skaller
2004-07-28  1:05   ` briand
2004-07-28  1:43     ` Brian Hurt
2004-07-28  2:49       ` briand
2004-07-28  3:12         ` Brian Hurt [this message]
2004-07-28  3:20         ` Brian Hurt
2004-07-28  5:54         ` brogoff
2004-07-28  7:22           ` Alex Baretta
2004-07-28 16:38             ` brogoff
2004-07-28 19:40               ` Jon Harrop
2004-07-28 20:18                 ` Brandon J. Van Every
2004-07-29  6:01                   ` Alex Baretta
2004-07-28 21:22                 ` brogoff
2004-07-29  9:13                   ` Daniel Andor
2004-07-29  9:25                     ` Keith Wansbrough
2004-07-29  9:41                       ` Nicolas Cannasse
2004-07-29  9:57                       ` Xavier Leroy
2004-07-29 10:44                         ` Daniel Andor
2004-07-29 12:56                           ` brogoff
2004-07-29 10:11                     ` skaller
2004-07-29 12:41                     ` brogoff
2004-07-29  6:28               ` Alex Baretta
2004-07-29 14:58                 ` brogoff
2004-07-29 16:12                   ` Brian Hurt
2004-07-29 17:49                     ` james woodyatt
2004-07-29 19:25                       ` Brian Hurt
2004-07-29 20:01                         ` brogoff
2004-07-30  4:42                           ` james woodyatt
2004-07-29 17:44                   ` james woodyatt
2004-07-29 23:12                     ` skaller
2004-07-29 22:42                   ` Alex Baretta
2004-07-30  2:38                     ` Corey O'Connor
     [not found]                     ` <200407300136.14042.jon@jdh30.plus.com>
2004-07-30 12:45                       ` Alex Baretta
2004-07-30 17:07                     ` brogoff
2004-07-30 18:25                       ` [Caml-list] kaplan-okasaki-tarjan deque (was "looping recursion") james woodyatt
2004-07-30 21:20                         ` brogoff
2004-07-31  5:37                           ` james woodyatt
2004-07-28  7:27       ` [Caml-list] looping recursion skaller
2004-07-28 14:36         ` Brian Hurt
2004-07-28 22:05           ` skaller
2004-07-28  0:37 ` skaller

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=Pine.LNX.4.44.0407272201480.6739-100000@localhost.localdomain \
    --to=bhurt@spnz.org \
    --cc=briand@aracnet.com \
    --cc=caml-list@inria.fr \
    --cc=j.prevost@gmail.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 NNTP newsgroup(s).