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 LAA22559; Sun, 30 Mar 2003 11:52:35 +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 LAA22588 for ; Sun, 30 Mar 2003 11:52:34 +0200 (MET DST) Received: from inria.fr (planar.net0.nerim.net [213.41.168.102]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h2U9qX501857 for ; Sun, 30 Mar 2003 11:52:34 +0200 (MET DST) Date: Sun, 30 Mar 2003 11:53:00 +0200 Subject: Re: [Caml-list] newbie questions Content-Type: text/plain; charset=US-ASCII; format=flowed Mime-Version: 1.0 (Apple Message framework v551) From: Damien Doligez To: caml-list@inria.fr Content-Transfer-Encoding: 7bit In-Reply-To: <20030329084839.BAF874C99@sitemail.everyone.net> Message-Id: <648DC56F-6295-11D7-B6B4-0003930FCE12@inria.fr> X-Mailer: Apple Mail (2.551) X-Spam: no; 0.00; damien:01 caml-list:01 newbie:01 'g':01 inference:01 algol:01 implicitly:01 haskell:01 recursion:01 gcc:01 ocamlopt:01 inefficient:01 -bit:01 compilers:01 rec:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Saturday, March 29, 2003, at 09:48 AM, Dr.Dr.Ruediger M.Flaig wrote: > let ht x = (String.sub x 1 ((String.length x)-1)), String.make 1 > (compl x.[0]);; Any program that uses this function is going to be horribly inefficient. You should do something like this instead: let string_map f s = let result = String.copy s in for i = 0 to (String.length s - 1) do result.[i] <- f s.[i]; done; result ;; let compl = function 'g' -> 'c' | 'c' -> 'g' | 'a' -> 't' | 't' -> 'a' | _ -> ' ';; let complement s = string_map compl s;; This should be able to handle the complete human genome (a 3 gigabyte string) without problems (on a 64-bit machine with enough memory). > 2.: A question on language design: why do recursive functions have to > be marked explicitly as such? My personal feeling is that this rather > spoils the nifty inference system... from Algol to Java, procedural > compilers require explicit type definitions but are able to work out > for themselves if a routine is recursive, All these language have different syntax for defining functions/procedures and for defining values, and make functions implicitly recursive. In effect, you are "marking" your functions as recursive by defining them. You can get the same effect in O'Caml by always using "let rec" for your functions. > and Haskell also has both type inference and implicit recursion, so > this should not be too difficult. Or has there anything escaped my > attention? Haskell is a lazy language, and has no problem with arbitrary recursive values. In a strict language like O'Caml, we cannot make all values recursive by default. > hence I would like to have some output in legible form but the -S > option does not seem to work properly. Does anybody know about this? Do you mean gcc -S or ocamlopt -S ? They both work on my MacOS X. -- Damien ------------------- 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