caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Damien Doligez <Damien.Doligez@inria.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] newbie questions
Date: Sun, 30 Mar 2003 11:53:00 +0200	[thread overview]
Message-ID: <648DC56F-6295-11D7-B6B4-0003930FCE12@inria.fr> (raw)
In-Reply-To: <20030329084839.BAF874C99@sitemail.everyone.net>

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


  parent reply	other threads:[~2003-03-30  9:52 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
2003-03-30  9:53 ` Damien Doligez [this message]
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=648DC56F-6295-11D7-B6B4-0003930FCE12@inria.fr \
    --to=damien.doligez@inria.fr \
    --cc=caml-list@inria.fr \
    /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;
as well as URLs for NNTP newsgroup(s).