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 IAA12885; Sun, 24 Jun 2001 08:03:46 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id IAA12930 for ; Sun, 24 Jun 2001 08:03:45 +0200 (MET DST) Received: from hotmail.com (f178.law15.hotmail.com [64.4.23.178]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f5O63in14250 for ; Sun, 24 Jun 2001 08:03:44 +0200 (MET DST) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Sat, 23 Jun 2001 23:03:43 -0700 Received: from 65.26.148.207 by lw15fd.law15.hotmail.msn.com with HTTP; Sun, 24 Jun 2001 06:03:43 GMT X-Originating-IP: [65.26.148.207] From: "Jeremy Fincher" To: caml-list@inria.fr Subject: Re: [Caml-list] New to OCaml: can someone explain how this code can be done better? Date: Sun, 24 Jun 2001 02:03:43 -0400 Mime-Version: 1.0 Content-Type: text/plain; format=flowed Message-ID: X-OriginalArrivalTime: 24 Jun 2001 06:03:43.0349 (UTC) FILETIME=[6C390A50:01C0FC73] Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Thanks! Going through and understanding your code helped me a lot, and was a terrific aid in seeing the functional (rather than imperative) way of looping. One question, though: > let explode string = > let rec loop i acc = > if i = 0 then acc > else let i' = i-1 in loop i' (string.[i'] :: acc) > in > loop (String.length string) [] Could this be rewritten as this, to remove the if/else? -- let explode string = let rec loop acc = function | 0 -> acc | i -> loop (string.[i-1] :: acc) (i-1) in loop [] (String.length string) Thanks for your excellent examples. Jeremy > > let implode list = > let string = String.create (List.length list) in > let rec loop i = function > | x :: rest -> string.[i] <- x; loop (i+1) rest > | [] -> () > in > loop 0 list; > string > > let permute_string s = > List.map implode (permute (explode s)) > >(* Eric Cooper, ecc@cmu.edu *) _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com ------------------- 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