From: Sylvain LE GALL <sylvain.le-gall@polytechnique.org>
To: flaig@hallucinogene.sanctacaris.net
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] newbie questions
Date: Sat, 29 Mar 2003 12:04:58 +0100 [thread overview]
Message-ID: <20030329110458.GA21457@gallu.home.net> (raw)
In-Reply-To: <20030329084839.BAF874C99@sitemail.everyone.net>
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
next prev parent reply other threads:[~2003-03-29 11:05 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-03-29 8:48 Dr.Dr.Ruediger M.Flaig
2003-03-29 9:15 ` Basile STARYNKEVITCH
2003-03-29 11:04 ` Sylvain LE GALL [this message]
2003-03-30 9:53 ` Damien Doligez
2003-03-30 14:23 ` Wolfgang Lux
-- strict thread matches above, loose matches on Subject: below --
2001-12-11 0:25 Jose A. Ortega Ruiz
2001-12-11 2:32 ` Mike Leary
2001-12-11 10:23 ` Sven
2001-08-22 17:58 Collin Monahan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20030329110458.GA21457@gallu.home.net \
--to=sylvain.le-gall@polytechnique.org \
--cc=caml-list@inria.fr \
--cc=flaig@hallucinogene.sanctacaris.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox