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 MAA01297; Sat, 29 Mar 2003 12:05:08 +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 MAA02617 for ; Sat, 29 Mar 2003 12:05:03 +0100 (MET) Received: from mwinf0202.wanadoo.fr (smtp5.wanadoo.fr [193.252.22.29]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h2TB51517630 for ; Sat, 29 Mar 2003 12:05:02 +0100 (MET) Received: from ptit-gallu.home.net (AVelizy-112-1-5-121.abo.wanadoo.fr [81.48.248.121]) by mwinf0202.wanadoo.fr (Postfix) with ESMTP id C68B2A400110; Sat, 29 Mar 2003 12:04:59 +0100 (CET) Received: from gallu.home.net ([192.168.0.12]) by ptit-gallu.home.net with esmtp (Exim 3.35 #1 (Debian)) id 18zE8t-0008Q5-00; Sat, 29 Mar 2003 12:04:55 +0100 Received: from gildor by gallu.home.net with local (Exim 3.36 #1 (Debian)) id 18zE8w-0005bQ-00; Sat, 29 Mar 2003 12:04:58 +0100 Date: Sat, 29 Mar 2003 12:04:58 +0100 To: flaig@hallucinogene.sanctacaris.net Cc: caml-list@inria.fr Subject: Re: [Caml-list] newbie questions Message-ID: <20030329110458.GA21457@gallu.home.net> References: <20030329084839.BAF874C99@sitemail.everyone.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030329084839.BAF874C99@sitemail.everyone.net> User-Agent: Mutt/1.5.3i From: Sylvain LE GALL X-Spam: no; 0.00; gall:01 le-gall:01 caml-list:01 newbie:01 neophyte:01 recursion:01 haskell:01 erlang:01 slower:01 'g':01 bug:01 biological:99 ocaml:01 caml:01 token:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sat, Mar 29, 2003 at 12:48:39AM -0800, Dr.Dr.Ruediger M.Flaig wrote: > Good morning to all you bedouins out there :-) , > > as I am a neophyte to CAML, forgive me if my questions have been asked (and answered) a hundred times before... > > > 1.: Is there any means of doing list-type pattern matching (style "| h::t -> ...") for recursion on strings? OK., I have realized that not having a decent string type is one of the reason why programs in Haskell or Erlang are much slower than in CAML, and resorted to a "roll-your-own" for dealing with this: > As i see your code, i think you maybe miss something in caml : typing help you to program ! If i have understood, you work on DNA code. In my mind DNA base type should be : in dna.ml type dna = A | C | G | T ( and arn = A | C | G | U ) type gene = dna list let ht x = match x with A -> T | T -> A | G -> C | C -> G (* give you the ht transform of you DNA list *) let complement lst = List.iter ht lst If you want more pattern matching : let ht_exp lst = match lst with A :: A :: A :: tl_lst -> T :: ( ht_exp tl_lst ) | A :: x :: A :: tl_lst -> T :: (ht x) :: (ht_exp tl_lst) ...usw Iy you want to convert your string to dna type : in parser_dna.mly %token A %token T %token C %token G %token EOF %start main %type main %% main: A main { Dna.A :: $2 } |C main { Dna.C :: $2 } |T main { Dna.T :: $2 } |G main { Dna.G :: $2 } |EOF { [] } ; in lexer_dna.mll { open Parser_dna } rule token = parse 'a' { A } | 't' { T } | 'c' { C } | 'g' { G } | eof { EOF } and then you can transform a string with let lexbuf = Lexing.from_string "acgtacgt" in let result = Parser_dna.main Lexer_dna.token lexbuf and result will contain [ A ; C ; G ; T; A; C; G; T ] I am not sure that is what you want. But when you program in Ocaml, i think it is better to use it as ocaml ( not trying to use techniques you should have used in other languages ). I hope it will help you. I have just typed the code as it comes, it is surely full of bug. Kind regard Sylvain LE GALL ps : i am surely not a genetic expert... there is maybe a lot of biological non sense. ------------------- 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