Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Francois Pessaux <pessaux@pauillac.inria.fr>
To: Jean.Luc.Paillet@lim.univ-mrs.fr
Cc: caml-list@inria.fr
Subject: Re: sequencing
Date: Tue, 03 Jun 1997 13:14:00 +0200	[thread overview]
Message-ID: <199706031114.NAA29905@pauillac.inria.fr> (raw)
In-Reply-To: Your message of "Tue, 03 Jun 1997 10:04:55 BST." <9706030959.AA15419@gyptis.univ-mrs.fr>


>    Quelqu'un pourrait-il m'expliquer pourquoi le sequencement d'une fonction
> a` effet de bord, telle que "print_string" par exemple, semble inverse'
> quand elle est appliquée sur une liste au moyen d'un iterateur.

Il se trouve que l'ordre d'evaluation (droite-gauche ou gauche-droite) n'est
pas specifie pour le compilo Caml. Autrement dit, il ne faut pas compter sur
un ordre particulier pour faire un programme correct. Sur la version de Caml
que tu utilise l'evaluation doit vraissemblablement se faire de droite a
gauche et la fonction map doit etre definie comme :
let rec map f = function
 | [] -> []
 | h :: q -> (f h) :: (map f q) ;;

Pour patcher ca, et ne plus etre dependant de l'ordre d'evaluation, il faut
effectuer explicitement le calcul de f h en premier :
let rec map f = function
    [] -> []
  | h :: q -> let r = f a
               in r :: map f q ;;

C'est d'ailleurs comme ca qu'est codee map en Objective Caml.

-- 
(*                      Francois PESSAUX (Francois.Pessaux@inria.fr) *)
(*                               INRIA Rocquencourt - Projet CRISTAL *)
(*                               (http://pauillac.inria.fr/~pessaux) *)
;;






  reply	other threads:[~1997-06-03 15:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-06-03  9:04 sequencing Jean.Luc.Paillet
1997-06-03 11:14 ` Francois Pessaux [this message]
1997-06-03 11:15 ` sequencing Jean-Christophe Filliatre
1997-06-03 11:56 ` sequencing Michel Quercia
1997-06-03 14:47 ` sequencing Vincent Poirriez

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=199706031114.NAA29905@pauillac.inria.fr \
    --to=pessaux@pauillac.inria.fr \
    --cc=Jean.Luc.Paillet@lim.univ-mrs.fr \
    --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