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 PAA18982; Sun, 26 Aug 2001 15:57:47 +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 PAA19039 for ; Sun, 26 Aug 2001 15:57:46 +0200 (MET DST) Received: from margaux.inria.fr (margaux.inria.fr [128.93.8.2]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f7QDvkj02561 for ; Sun, 26 Aug 2001 15:57:46 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by margaux.inria.fr (8.7.6/8.7.3) with ESMTP id PAA18098 for ; Sun, 26 Aug 2001 15:57:46 +0200 (MET DST) Received: from smtp.noos.fr (aragon.noos.net [212.198.2.75]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f7QDvjj02557 for ; Sun, 26 Aug 2001 15:57:45 +0200 (MET DST) Message-Id: <200108261357.f7QDvjj02557@concorde.inria.fr> Received: (qmail 5555810 invoked by uid 0); 26 Aug 2001 13:57:45 -0000 Received: from unknown (HELO localhost) ([212.198.203.74]) (envelope-sender ) by 212.198.2.75 (qmail-ldap-1.03) with SMTP for ; 26 Aug 2001 13:57:45 -0000 Date: Sun, 26 Aug 2001 15:57:45 +0200 Content-Type: text/plain; format=flowed; charset=iso-8859-1 X-Mailer: Apple Mail (2.388) From: =?iso-8859-1?Q?Laurent_Ch=E9no?= To: Caml-list Mime-Version: 1.0 (Apple Message framework v388) In-Reply-To: <0108261423530A.02716@ice> Subject: Re: [Caml-list] Queens examples Content-Transfer-Encoding: quoted-printable Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk (* please excuse my poor english *) Le dimanche 26 ao=FBt 2001, =E0 01:33, Gerd Stolpmann a =E9crit : > For example, look at the definition of concmap: > > let rec concmap f =3D function > | [] -> [] > | h :: t -> f h (concmap f t);; > > The point is that the recursive call (concmap f t) occurs within an=20 > expression, > and the current execution environment must be saved on the stack = before=20 > the > self-invocation such that it is still available when the containing=20 > expression > (f h (concmap f t)) is being evaluated. This is what all programming=20= > languages > do when recursive definitions are executed. > > You can avoid that only by changing the algorithm, i.e. avoid concmap=20= > (and > perhaps filter_append). The simplest way is to make some parts of the=20= > program > imperative, because managing the stack effectively can be _very_=20 > difficult for > purely functional programming. You can avoid the stack problem by writing (still functionnaly) : let concmap f l =3D let rec aux result =3D function | [] -> result | h :: t -> aux (f h result) t in aux [] (List.rev l) ;; Of course, List.rev has been written with terminal recursion, like this = : let reverse l =3D let rec aux result =3D function | [] -> result | h :: t -> aux (h :: result) t in aux [] l ;; (compare the two functions... !) Best regards, Laurent ------------------- 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