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 SAA08087; Fri, 12 Apr 2002 18:59:52 +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 SAA03373 for ; Fri, 12 Apr 2002 18:59:51 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from mel-rto2.wanadoo.fr (smtp-out-2.wanadoo.fr [193.252.19.254]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g3CGxpL20792 for ; Fri, 12 Apr 2002 18:59:51 +0200 (MET DST) Received: from mel-rta9.wanadoo.fr (193.252.19.69) by mel-rto2.wanadoo.fr; 12 Apr 2002 18:59:50 +0200 Received: from debian (80.8.79.225) by mel-rta9.wanadoo.fr; 12 Apr 2002 18:59:28 +0200 Received: from moi by debian with local (Exim 3.35 #1 (Debian)) id 16w4Oa-0000Qt-00 for ; Fri, 12 Apr 2002 18:59:32 +0200 To: caml-list@inria.fr Subject: Re: [Caml-list] Simple question References: <20020412164400.60556.qmail@web13002.mail.yahoo.com> From: Remi VANICAT Date: 12 Apr 2002 18:59:32 +0200 In-Reply-To: <20020412164400.60556.qmail@web13002.mail.yahoo.com> Message-ID: <87k7rcn98r.dlv@wanadoo.fr> User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Eric Merritt writes: > let me start off by saying that if this is not the > place to post this type of question please direct me > to the correct list/group. I am picking up ocaml, > starting off by doing a few simple things. I am at > somewhat of an impass here in that I cannot figure out > why the function below gives me type errors. It works > fine if I leave it non-tail recursive, but as soon as > I put in an accumulator and make it tail-recursive it > fails to compile. If one of you could please point me > in the right direction for solving this problem that > would be great. btw this is only for my own > edification. > > let rec apply_fun_list x f_list accm = > match f_list with > h::t -> > apply_fun_list x t accum::(h x) > | [] -> > accum::[];; :: is the constructor that add something at the beginning of the list. so you may want to say : let rec apply_rev_fun_list x f_list accum = match f_list with | h::t -> apply_fun_list x t (h t)::accum | [] -> accum but there, the function will reverse the list. It might not be what you want (but List.rev is tail recursive) by the way, I would have wrote it like : let rec apply_fun_list x f_list = List.map (fun h -> h x) f_list but List.map is not tail recursive.... -- Rémi Vanicat vanicat@labri.u-bordeaux.fr http://dept-info.labri.u-bordeaux.fr/~vanicat ------------------- 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