caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Alessandro Baretta <alex@baretta.com>
To: Ocaml <caml-list@inria.fr>
Subject: [Caml-list] Wasn't O'Caml a functional language?
Date: Sun, 22 Sep 2002 00:47:20 +0200	[thread overview]
Message-ID: <3D8CF6F8.2050904@baretta.com> (raw)

First of all, allow me to RTFM myself before anybody else 
does. I just spent the last hour or so tracking down a bug 
caused by the "procedural-style" side-effect in Queue.iter: 
the queue is actually emptied by that function. Now, if 
O'Caml is a functional language, and Queue.iter is a 
functional iterator, why is there a need for that very 
counterintuitive side-effect? If I use List.iter on a list, 
I do not expect it to flush my list of all it's contents. 
The same with a Hashtbl.iter, and in general with all 
functional iterators, which are the very heart of the 
standard library.

In my opinion, "The Right Way (TM)" to use datastructures in 
O'Caml and in functional languages in general is to build 
them, iterate non-destructively over them as many times as 
necessary, and finally let the GC reclaim them when they are 
no longer accessible from the live scope. What makes this 
approach much simpler to handle, much more intuitive to 
understand and less intricate to debug, is that data 
structure aliasing does not have to be explicitly taken into 
account. On the other hand, if one uses iterators with 
side-effects and the data structures are aliased--as was my 
case in my application, until I figured out what was going 
wrong--all sorts of weird non-local bugs can appear, and 
tracking them down can take quite a few runs of ocamldebug.

Concluding, let me "break a spear"--as we say in Italian--in 
favor of a purely functional standard library, where such 
datastructures as Queue.t's and the like can be freely 
aliased without a second thought.

Cheers, and back to work...

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


             reply	other threads:[~2002-09-21 22:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-21 22:47 Alessandro Baretta [this message]
     [not found] ` <15756.65084.40025.869484@spike.artisan.com>
2002-09-21 23:47   ` Alessandro Baretta
2002-09-22  4:23     ` [Caml-list] " Michaël Grünewald
2002-09-23 10:40       ` Pixel
2002-09-24  8:45       ` Alessandro Baretta
     [not found]         ` <15760.15527.648990.807473@hod.void.org>
2002-09-24 13:32           ` Alessandro Baretta

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=3D8CF6F8.2050904@baretta.com \
    --to=alex@baretta.com \
    --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;
as well as URLs for NNTP newsgroup(s).