caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: brogoff <brogoff@speakeasy.net>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] OCaml troll on Slashdot
Date: Thu, 17 Mar 2005 10:06:45 -0800 (PST)	[thread overview]
Message-ID: <Pine.LNX.4.58.0503170931300.30293@shell2.speakeasy.net> (raw)
In-Reply-To: <200503171016.18310.jon@ffconsultancy.com>

On Thu, 17 Mar 2005, Jon Harrop wrote:
> On Thursday 17 March 2005 03:48, Yaron Minsky wrote:
> > On Wed, 16 Mar 2005 19:35:17 -0800 (PST), brogoff
> > <brogoff@speakeasy.net> wrote:
> > > Anyways, long lists do occur, and Stack_overflow at the customer site
> > > sucketh bigtime.
> >
> > I completely agree.  As someone who makes extensive use of OCaml in a
> > business setting, the fact that the standard libraries throw
> > exceptions on large data structures is a real pain.
>
> I believe the Stack_overflow exception is not necessarily thrown - the process
> may simply die. IIRC, I found this on x86 Debian Linux when swap was turned
> off.
>
> > It's a violation
> > of the principle of least surprise, and I've run into it in practice
> > quite a few times.
>
> I understand your (and Brian's) concern but I think the solution is to be more
> careful when programming, rather than to replace all of the library
> functions. That seems like a sledgehammer to crack a nut to me...

There are a few problems with that suggestion. The cases where I've been bitten
didn't have lists of length 100_000 (or whatever the rather arbitrary number
above which we're not supposed to use lists) but rather had quite a few lists
that were close enough to that number, and the maps (appends, etc.) were being
called inside other mapping functions, on other lists.

Also, as I state above, the number is arbitrary, and having OCaml choke at some
particular size rather than letting me use large lists violates that least
surprise principle. I had an offline discussion recently with another caml-list
person in which he told me that he wished OCaml used Bignums instead of int's
by default. I disagree, but I don't think it's a dumb idea. The behavior of
the standard List functions is worse IMO. Maybe the standard Lisp.map should be
named List.unsafe_map (1/2 :-))?

I realize that this problem can be coded around, sometimes with better data
structures, or by the double reversing approach (which is what I used to use)
but my own sense of programming language aesthetics is that this is a flaw, or
at least a hole in the language that should be filled one day.

> > We're happy to make the performance
> > tradeoff.  If we really want things to be fast, List.map is no good
> > anyway, due to the lack of inlining of the function parameter.

That's quite true. However, Yaron, I bet you usually write the program with map
first, and then optimize later iff it isn't fast enough, right? Manual inlining
makes code uglier.

> Yes, if your program uses non-tail-recursive functions with very deep
> recursion then it will be much slower anyway. Consequently, you are likely to
> fix this whilst optimising anyway.
>
> As Brian has said before, users can throw you a sideball by giving input which
> requires deep recursion by a non-tail-recursive function which had not been
> expected by the programmer. Provided you are thorough, this shouldn't happen
> though.

As I said above, you can have "not so deep recursions" nested inside each other
many times, leading to a deep recursion. Besides, "deep" is arbitrary.

> I must say that I've had fewer stack problems with my OCaml code than with
> code I've used in other languages...

Absolutely correct, and my whining should in no way be construed as saying
that OCaml sucks. However, when the language is so good, it's users begin to
desire perfection. When a language is like, say C++ or Perl, then Ada and
Python look really good.

>
> > I do think that it would be a great thing if the tail-recursive list
> > functions were moved into the standard library.
>
> I would not like to see trivial tail-recursive alternatives put into the
> library (e.g. let map f l = rev_map f (rev l)).


I agree with you here, and I'm only beating this dead dromedary to keep up the
pressure for a better solution. It's known in theory how to better than
the double rev solution, but as Jacques pointed out (and I accept his
counterexample for now!) there may be implications on GC which still give a
slight edge to the non tail recursive versions for smaller lists.

-- Brian


  parent reply	other threads:[~2005-03-17 18:06 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-15  1:29 Karl Zilles
2005-03-15  8:32 ` [Caml-list] " Oliver Bandel
2005-03-15  8:45   ` Michael Vanier
2005-03-15  8:59     ` Jon Harrop
2005-03-15 20:17       ` Yoann Padioleau
2005-03-15 20:36         ` Jon Harrop
2005-03-15 21:03           ` padiolea
2005-03-15 21:40             ` William D.Neumann
2005-03-15 22:12               ` Yoann Padioleau
2005-03-15 23:07                 ` William D.Neumann
2005-03-15 23:39                   ` Jon Harrop
2005-03-15 23:54                     ` Thomas Fischbacher
2005-03-16  0:03                   ` Christopher Dutchyn
2005-03-16  0:18                   ` Oliver Bandel
2005-03-16  1:05                     ` Yoann Padioleau
2005-03-16  2:55                       ` Oliver Bandel
2005-03-16 11:23                         ` Thomas Fischbacher
2005-03-16 23:41                           ` Oliver Bandel
2005-03-16 13:33                         ` Yoann Padioleau
2005-03-16 23:59                           ` Oliver Bandel
2005-03-16  3:01                     ` Jon Harrop
2005-03-16 13:10                       ` Yoann Padioleau
2005-03-16 13:41                         ` Jacques Garrigue
2005-03-16 14:14                           ` Yoann Padioleau
2005-03-17  0:27                             ` Oliver Bandel
2005-03-16 17:43                           ` brogoff
2005-03-16 19:51                             ` Jon Harrop
2005-03-17  3:35                               ` brogoff
2005-03-17  3:48                                 ` Yaron Minsky
2005-03-17 10:16                                   ` Jon Harrop
2005-03-17 10:47                                     ` Oliver Bandel
2005-03-17 18:06                                     ` brogoff [this message]
2005-03-17 19:15                                       ` Marcin 'Qrczak' Kowalczyk
2005-03-18 17:46                                         ` brogoff
2005-03-18 18:44                                           ` Marcin 'Qrczak' Kowalczyk
2005-03-17 21:31                                       ` Oliver Bandel
2005-03-17  9:45                                 ` Christian Szegedy
2005-03-17 10:31                                 ` Jon Harrop
2005-03-17 11:11                                   ` Ville-Pertti Keinonen
2005-03-17 11:31                               ` tail-recursion vs. no tail-recursion in list functions sebastian.egner
2005-03-17 21:41                                 ` [Caml-list] " Oliver Bandel
2005-03-18  0:04                                   ` David Brown
2005-03-18  0:06                                   ` Karl Zilles
2005-03-18  1:13                                 ` Jacques Garrigue
2005-03-17  0:21                             ` [Caml-list] OCaml troll on Slashdot Oliver Bandel
2005-03-17  1:05                             ` Jacques Garrigue
2005-03-17 17:32                             ` Jason Hickey
2005-03-17 19:06                               ` Marcin 'Qrczak' Kowalczyk
2005-03-17  0:14                           ` Oliver Bandel
2005-03-16  1:38             ` Jacques Garrigue
2005-03-31 11:42         ` Paul Argentoff
2005-03-31 11:41       ` Paul Argentoff
2005-03-15 20:06   ` Yoann Padioleau
2005-03-15  9:25 ` Richard Jones
2005-03-15 10:08   ` YANG Shouxun
2005-03-15 20:02     ` Yoann Padioleau
2005-03-15 22:33       ` Richard Jones
2005-03-16  1:33       ` YANG Shouxun
2005-03-15 10:34   ` padiolea
2005-03-15 10:52     ` Diego Olivier Fernandez Pons
2005-03-15 14:12     ` Eijiro Sumii
2005-03-15 15:25       ` Christophe TROESTLER
2005-03-15 18:05         ` Thomas Fischbacher
2005-03-15 18:26           ` Kip Macy
2005-03-16  0:32             ` Oliver Bandel
2005-03-16 11:26             ` David Fox
2005-03-15 18:55         ` Christopher A. Watford
2005-03-15 19:56           ` Jon Harrop
2005-03-16  0:35             ` Oliver Bandel
2005-03-16  0:34           ` Oliver Bandel
2005-03-18  6:04 Harrison, John R

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.58.0503170931300.30293@shell2.speakeasy.net \
    --to=brogoff@speakeasy.net \
    --cc=caml-list@yquem.inria.fr \
    /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).