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 LAA22617; Thu, 5 Dec 2002 11:01:05 +0100 (MET) 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 LAA22183 for ; Thu, 5 Dec 2002 11:01:03 +0100 (MET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id gB5A0qX06843; Thu, 5 Dec 2002 11:00:52 +0100 (MET) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA22469; Thu, 5 Dec 2002 11:00:51 +0100 (MET) From: Pierre Weis Message-Id: <200212051000.LAA22469@pauillac.inria.fr> Subject: Re: [Caml-list] function In-Reply-To: <20021203232211.GC22545@beech> from Issac Trotts at "Dec 3, 102 03:22:11 pm" To: ijtrotts@ucdavis.edu (Issac Trotts) Date: Thu, 5 Dec 2002 11:00:50 +0100 (MET) Cc: caml-list@inria.fr X-Mailer: ELM [version 2.4ME+ PL28 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > On Mon, Dec 02, 2002 at 04:55:06PM +0100, altavillasalvatore@libero.it wrote: > > Hi all, > > I would want to know if a function exists that allows me to make this: > > > > ["123";"45";"678"] -> [1;2;3;4;5;6;7;8;]. > > let f l = > let ret = ref [] in > String.iter > (fun c -> ret := ((int_of_char c) - (int_of_char '0')) :: !ret) > (List.fold_left (^) "" l); > List.rev !ret;; > > f ["123";"45";"678"];; > > Cheers, > Issac Trotts If you like puzzles, here is an additional exercise: 00) List which parens are useless in this code, according to which rules given in the simple guide-lines and syntactic conventions of http://pauillac.inria.fr/caml/FAQ/qrg-eng.html#parens and http://pauillac.inria.fr/caml/FAQ/pgl-eng.html#parens. 0) Rewrite this code to a more suitable form for a beginner, i.e. in a purely functional style with no side effect. 1) Try to avoid the useless List.rev at the end. 2) What is the complexity of your function f ? 3) Explain why the List.fold_left application is not only over complex but also runtime over consuming. Hope this helps. Cheers, Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/ ------------------- 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