From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA05465; Fri, 3 Aug 2001 15:26:42 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA05496 for ; Fri, 3 Aug 2001 15:26:41 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f73DQWD26642; Fri, 3 Aug 2001 15:26:32 +0200 (MET DST) Received: (from fpottier@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA05545; Fri, 3 Aug 2001 15:26:31 +0200 (MET DST) Date: Fri, 3 Aug 2001 15:26:31 +0200 From: Francois Pottier To: Johann Spies Cc: caml-list@inria.fr Subject: [Caml-list] Re: your mail Message-ID: <20010803152631.A5405@pauillac.inria.fr> Reply-To: Francois.Pottier@inria.fr References: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Mailer: Mutt 1.0i In-Reply-To: ; from jspies@maties.sun.ac.za on Fri, Aug 03, 2001 at 10:58:03AM +0000 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > Someone wrote: > > > I would recommend not to use print_string as long as > > you're not comfortable with the language; writing purely > > functional code (no side effects) will be easier. > > I have always used print statements in programs to help me with > debugging and to see what is going on (that is besides the necessity > to get some output from the program). A program with no side effects > does not make sense to me. What is the use of it? I am the one who wrote that, so I'll clarify. Clearly, you are right in thinking that `real' programs must have side effects. However, the interactive environment (also known as the `toplevel loop') allows you to evaluate expressions (that is, program fragments) which have no side effects and to examine their result. This can be very useful. For instance, consider the following interactive session: $ ocaml Objective Caml version 3.02 # let rec increment_list = function | [] -> [] | element :: rest -> (element + 1) :: (increment_list rest) ;; val increment_list : int list -> int list = # increment_list [1;2;3];; - : int list = [2; 3; 4] Here, I have defined a function of one argument, which accepts an integer list and returns a list where all elements have been incremented by 1. The function has no side effects (it does not print anything), yet you can easily test it and see how it works. I hope this helps, -- François Pottier Francois.Pottier@inria.fr http://pauillac.inria.fr/~fpottier/ ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr