caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Francois Pottier <Francois.Pottier@inria.fr>
To: Johann Spies <jspies@maties.sun.ac.za>
Cc: caml-list@inria.fr
Subject: [Caml-list] Re: your mail
Date: Fri, 3 Aug 2001 15:26:31 +0200	[thread overview]
Message-ID: <20010803152631.A5405@pauillac.inria.fr> (raw)
In-Reply-To: <E15SceZ-0002Rv-00@bywoner>; from jspies@maties.sun.ac.za on Fri, Aug 03, 2001 at 10:58:03AM +0000


> 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 = <fun>
  # 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


  reply	other threads:[~2001-08-03 13:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-03 10:58 Johann Spies
2001-08-03 13:26 ` Francois Pottier [this message]
2001-08-03 17:42 ` [Caml-list] Re: your mail Vitaly Lugovsky
2001-08-03 18:23 ` [Caml-list] Please help a newbie md5i
2001-08-05 21:37   ` John Max Skaller
2001-08-06 10:02     ` empty type (was [Caml-list] Please help a newbie) Hendrik Tews
2001-08-07 17:32       ` John Max Skaller
  -- strict thread matches above, loose matches on Subject: below --
2003-02-07  5:23 Nikolaj Bjorner
2003-02-07 13:10 ` [Caml-list] Re: your mail Mike Potanin
2002-01-21 23:27 cgillot
2002-01-21 22:43 ` [Caml-list] Re: your mail Markus Mottl
2002-01-22  9:00   ` Daniel de Rauglaudre
2002-01-22 13:12     ` Markus Mottl
2001-03-06 20:25 rakesh malhotra
2001-03-07 16:53 ` [Caml-list] Re: your mail Brian Rogoff

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=20010803152631.A5405@pauillac.inria.fr \
    --to=francois.pottier@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=jspies@maties.sun.ac.za \
    /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).