Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: 2003-03-29 (08:49)
From: Dr.Dr.Ruediger M.Flaig <flaig@h...>
Subject: [Caml-list] newbie questions
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:

let ht x = (String.sub x 1 ((String.length x)-1)), String.make 1 (compl x.[0]);;

because I think that

let compl = function 'g' -> 'c' | 'c' -> 'g' | 'a' -> 't' | 't' -> 'a' | _ -> ' ';;
let rec complement = function 
    "" -> ""
  | dna -> let h, t = ht dna in (complement h) ^ t;;

is much smarter than the iterative version

let compl = function 'g' -> 'c' | 'c' -> 'g' | 'a' -> 't' | 't' -> 'a' | _ -> ' ';;
let complement dna =
  let cdna = ref "" in
    for i = 0 to String.length( dna )-1 do 
      let cha = String.get dna i in
	cdna :=  (String.make 1 (compl cha)) ^ !cdna 

(Yes! Confess guilty! Learned Pascal in 1986...)

but -- and this is my point -- there should certainly be some more elegant way of dealing with this than the horrible "ht" definition, shouldn't it?

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, and Haskell also has both type inference and implicit recursion, so this should not be too difficult. Or has there anything escaped my attention?

3.: I have followed the thread about speed with considerable interest... my personal impression is that on a PPC processor, OCaml code is sometimes even faster than C code! (Does not hold true for dft, I admit.) This may have to do with the queer gcc supplied by Apple, which does not appear to make good use of the PPC's wealth of registers... 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?

Yours sincerely,

Dr. Dr. Ruediger Marcus Flaig
Institute for Immunology
University of Heidelberg
Im Neuenheimer Feld 305
D-69120 Heidelberg
Tel. +49-172-7652946
Fax  +49-4075110-17171

Free eMail .... the way it should be....

Select your own custom email address for FREE! Get w/No Ads, 6MB, POP & more!

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: