Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] newbie questions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Sylvain LE GALL <sylvain.le-gall@p...>
Subject: Re: [Caml-list] newbie questions
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 <Dna.gene> 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