caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Brian Hurt <brian.hurt@qlogic.com>
To: Karl Zilles <zilles@1969.ws>
Cc: "Daniel M. Albro" <albro@humnet.ucla.edu>, <caml-list@inria.fr>
Subject: Re: [Caml-list] OCaml popularity
Date: Thu, 13 Mar 2003 15:53:40 -0600 (CST)	[thread overview]
Message-ID: <Pine.LNX.4.33.0303131545310.2164-100000@eagle.ancor.com> (raw)
In-Reply-To: <3E70F854.7020705@1969.ws>

On Thu, 13 Mar 2003, Karl Zilles wrote:

> Daniel M. Albro wrote:
> > imperative side of the language will get fleshed out a bit with some
> > expanded loop features like break statements, 
> 
> You can always implement a break statement as an exception:
> 
> exception Break;;
> 
> try for i = 1 to 10 do
> 	if i == 5 then raise Break
> done with Break -> ();;
> 
> As an exception, you could (if you wanted) include special case handling 
> for the break, or create a more aptly named exception and pass through 
> data.

How efficient is this vr.s rewritting the loop as a tail recursion?  I.e.:

    let rec loop idx = 
        if (idx == 10) then () (* exit the loop *)
        else if special_case(idx) then () (* early exit of the loop *)
        else
        begin
            foo(idx);
            loop (idx + 1)
        end
    in
    loop 1

Naturally, instead of returning unit, the function can return whatever.
All for loops can be rewritten as while loops, and all while loops can be
rewritten as tail recursive functions.

What I'm worried about is the costs of throwing an exception.  This isn't
C++ (where throwing an exception needs to unroll the stack, calling all
the correct destructors, and can therefor be quite expensive), but that
doesn't mean exceptions are 'cheap'.  Exceptions, by definition, are
exceptional.  Were I writting the optimizer, I'd freely assume that any
code path that ends in throwing an exception is not a critical path and 
can be slow.

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


  parent reply	other threads:[~2003-03-13 21:43 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-13  7:09 Daniel M. Albro
2003-03-13 16:48 ` Neel Krishnaswami
2003-03-13 21:29 ` Karl Zilles
2003-03-13 21:36   ` Daniel M. Albro
2003-03-13 21:42   ` Daniel M. Albro
     [not found]     ` <15985.1204.814698.939943@h00045a4799d6.ne.client2.attbi.com>
2003-03-14  5:49       ` Daniel M. Albro
2003-03-14  9:05         ` Ville-Pertti Keinonen
2003-03-14  9:13           ` Daniel M. Albro
2003-03-13 21:53   ` Brian Hurt [this message]
  -- strict thread matches above, loose matches on Subject: below --
2003-03-15 16:27 Oliver Bandel
2003-03-15 17:55 ` Sergey Goldgaber
2003-03-14 22:14 Daniel M. Albro
2003-03-13 14:39 [oliver: Re: [Caml-list] OCaml popularity] Oliver Bandel
2003-03-13 16:35 ` [Caml-list] OCaml popularity Michael Schuerig
2003-03-12 23:53 [oliver: Re: [Caml-list] OCaml popularity] Oliver Bandel
2003-03-13  1:34 ` [Caml-list] OCaml popularity Michael Schuerig
2003-03-12 17:40 isaac gouy
2003-03-06 23:27 Graham Guttocks
2003-03-10 20:43 ` Paul Steckler
2003-03-10 23:48 ` Gerd Stolpmann
2003-03-11  0:18   ` Brian Hurt
2003-03-17 23:49   ` Graham Guttocks
2003-03-11  1:43 ` Nicolas Cannasse
2003-03-11 10:23   ` Pierre Weis
2003-03-11 14:27     ` Guillaume Marceau
2003-03-11 16:16       ` David Brown
2003-03-12  2:32       ` Nicolas Cannasse
2003-03-12 10:51         ` Alex Romadinoff
2003-03-12 18:24         ` Max Kirillov
2003-03-11 19:02     ` Graham Guttocks
2003-03-12 17:12       ` Richard W.M. Jones
2003-03-12 18:08         ` Alwyn Goodloe
2003-03-12 22:34           ` Michael Schuerig
2003-03-12 23:13             ` Martin Weber
2003-03-12 23:35               ` Michael Schuerig
2003-03-13  8:02                 ` Alessandro Baretta
2003-03-13 10:23                   ` Michael Schuerig
2003-03-12 23:35             ` Brian Hurt
2003-03-12 23:18         ` Daniel Bünzli
2003-03-12 23:47           ` Brian Hurt
2003-03-13  2:15         ` William Lovas
2003-03-13  3:44           ` Graham Guttocks
2003-03-13  9:31           ` Richard W.M. Jones
     [not found]           ` <20030313095232.GC347@first.in-berlin.de>
2003-03-13 20:50             ` William Lovas
2003-03-13 21:17               ` Oliver Bandel
2003-03-13 22:01                 ` Brian Hurt
2003-03-13 22:17                 ` Oliver Bandel
2003-03-14  6:33                 ` Michal Moskal
2003-03-14 11:50                   ` Markus Mottl
2003-03-14 15:38                     ` Oliver Bandel
2003-03-14 10:13               ` MikhailFedotov
2003-03-14 10:30                 ` Johann Spies
2003-03-13  8:09       ` Pierre Weis
2003-03-15  1:43     ` Tushar Samant
2003-03-15  8:19       ` Andreas Eder
2003-03-11 16:26   ` Fred Yankowski
2003-03-12 18:59 ` Martin Weber
2003-03-12 20:24   ` Xavier Leroy
2003-03-13  0:42   ` Graham Guttocks

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.33.0303131545310.2164-100000@eagle.ancor.com \
    --to=brian.hurt@qlogic.com \
    --cc=albro@humnet.ucla.edu \
    --cc=caml-list@inria.fr \
    --cc=zilles@1969.ws \
    /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).