Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: Andreas Rossberg <AndreasRossberg@web.de>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] List.rev
Date: 02 May 2004 23:29:57 +1000	[thread overview]
Message-ID: <1083504596.20722.308.camel@pelican.wigram> (raw)
In-Reply-To: <005001c4303e$00bf7730$7693b9d9@wiko>

On Sun, 2004-05-02 at 22:07, Andreas Rossberg wrote:
> > Yet it is easy enough to say
> >
> > O(n) time and O(1) stack
> 
> Sorry, but isn't talking about a stack even less meaningful
> implementation-driven "gibberish"? 

That depends on the conformance model. One can certainly
speak of auxilliary storage requirements. In C++, one can
be definite about STL heap storage (because the store
is obtained by definite calls to an allocator).

> Usually, a functional language definition
> does not mention anything like a stack. 

A purely semantic definition may well not.
Such a definition is generally considered inadequate
for a library precisely because it doesn't include
performance requirements.

> In fact, some major FP
> implementations don't even use a stack.

Indeed .. Felix doesn't use the machine stack for 
procedure calls, its incompatible with high speed
context switching of control inverted algorithms 
on a typical Unix box.

However, Ocaml does, and, the distinction between heap
and stack is actually quite important to many clients:
many systems have a lot of potential heap, but only limited
stack. That doesn't mean distinguishing auxilliary heap
and stack is the right thing to do. I think it might be,
but I don't know, and there is a value judgement involved
deciding how much freedom an implementor should have.

It isn't necessary to specify performance: but I do believe
there is a consensus to do so. Certainly that belief
is *firmly* held in the C++ world now, since STL introduced
the idea to the committee that such requirements were an
integral part of a specification.

[There is actually a story here: there was concern that
the requirements on STL Sort were so high that NO known
implementation could meet them bar one: the one Stepanov
provided, which was subject to a Patent held by HP.
HP was asked to relinquish its intellectual property rights
and did.]

So, I'm not desiring to force my view on what conformance
model should be used, and how tight the specs are,
only that if specs are given, they be normative
well formed coherent requirements.

Its quite possible to *define* the term 'tail-rec'
in the library preable and thereby avoid the current
problem that the requirement doesn't mean anything.

> Tail recursion at least is a clear syntactic property 

Yes. I agree. But the standard library isn't defined
in Ocaml but a more abstract semantics. Clearly one
wishes to allow for Ocaml implementations, C implementations,
and even machine code implementations.

The usual technique is to specify a machine abstraction,
define semantics in terms of that, and then bind the
compiler performance to the abstraction.

> That a tail-recursive
> function uses constant space is then a well-understood QOI issue. No serious
> FP implementation would dare not to meet this criterion.

First, Ocaml isn't a FP. One can certainly introduce
O(n) auxilliary store in a loop (or tail rec function)
using mutable state.

Second, I do agree that one expects a tail recursive calls
to be implemented as loops. This is a serious problem
in Felix because it generates C: procedures are easily
optimised: they never use C-stack except transiently, 
functions are not quite so easy because they do.

Third, tail-rec in Ocaml isn't quite so clear due to
exception handling (still well defined though).

Fourth, it is quite possible for a code to contain
both tail calls and non-tail calls: use linear stack,
instead of quadradic for example. Tail-rec or not
is too black and white.

Fifth: a tail rec function can still be high complexity.
It depends on the actual implementation. You CAN
sort a list using a tail-rec bubble sort... or a tail
rec function allocating n copies of the list for fun .. 
(yeah it still wouldn't blow the stack ..)

So generally, I do agree that the fact the Ocaml docs
now say 'tail-rec' where before there was no annotation at all:
this is a Good Thing (TM).

I don't want the implication removed from the library!
I'd just like to see it stated more normatively.
No hurry either. Just a note to think about, because there
are more and more people using Ocaml, and that does tend
to make any imprecision come out, especially new users
not familiar with the 'common understanding' about things
like 'tail-rec'.

BTW: for some STL algorithms, the EXACT number of calls
the algorithm makes to the copy constructor is mandated.
(The copy algorithm). The question arose if an implementation
was permitted to make a copy like this:

	tmp = *p++
	*q++ = tmp

and the answer is NO, that is banned. Exactly n calls are 
allowed and no more. Each object is copied *exactly* once.
No 'O' notation about it.

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net



-------------------
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-05-02 13:30 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-30 17:54 [Caml-list] "List.index" or "List.unique" functions? Rahul Siddharthan
2004-04-30 18:51 ` Martin Jambon
2004-04-30 19:01 ` Benjamin Geer
2004-04-30 19:07   ` Thanks " Rahul Siddharthan
2004-04-30 19:08 ` Karl Zilles
2004-04-30 19:29   ` Matthieu Sozeau
2004-04-30 20:01     ` Karl Zilles
2004-04-30 20:05   ` Remi Vanicat
2004-04-30 20:47     ` JM Nunes
2004-04-30 20:58       ` Karl Zilles
2004-05-01  1:59   ` [Caml-list] List.rev skaller
2004-05-01  4:18     ` Jon Harrop
2004-05-01  4:38     ` brogoff
2004-05-01  5:12       ` skaller
2004-05-01  7:08         ` William Lovas
2004-05-01  8:10           ` skaller
2004-05-01  8:32             ` Jon Harrop
2004-05-01  9:24               ` skaller
2004-05-02 12:07             ` Andreas Rossberg
2004-05-02 13:29               ` skaller [this message]
2004-05-01 10:07         ` Richard Jones
2004-05-01 10:09           ` Nicolas Cannasse
2004-05-02 16:04             ` Brian Hurt
2004-05-01 10:32           ` Jon Harrop
2004-05-01 16:41     ` John Goerzen
2004-05-01 19:11       ` skaller
2004-05-01 10:03 ` [Caml-list] "List.index" or "List.unique" functions? Richard Jones

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=1083504596.20722.308.camel@pelican.wigram \
    --to=skaller@users.sourceforge.net \
    --cc=AndreasRossberg@web.de \
    --cc=caml-list@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