Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Benjamin Canou <benjamin.canou@gmail.com>
To: caml-list@yquem.inria.fr
Cc: Jon Harrop <jon@ffconsultancy.com>
Subject: Re: [Caml-list] Strange performances
Date: Fri, 18 Jan 2008 20:53:19 +0100	[thread overview]
Message-ID: <1200685999.6345.40.camel@benjamin-laptop> (raw)
In-Reply-To: <200801181743.22912.jon@ffconsultancy.com>

Le vendredi 18 janvier 2008 à 17:43 +0000, Jon Harrop a écrit :
> As an aside, I would recommend using an imperative style with mutable data 
> structures like "string" are involved:
> 
>   let list_of_string string =
>     let list = ref [] in
>     for i = String.length string - 1 downto 0 do
>       list := string.[i] :: !list
>     done;
>     !list;;
> 

Actually, and as I said in my first message, it was a really naive
implementation, for which I used the more compact and quick to write
code.

Imho, I would not add references and write the function like this :

let list_of_string str =
  let rec aux i acc =
    if i < 0 then acc
    else aux (i - 1) (String.unsafe_get str i :: acc)
  in aux (String.length str - 1) []

But we are digressing...

  Benjamin.


  reply	other threads:[~2008-01-18 19:53 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-18  1:32 Benjamin Canou
2008-01-18  2:15 ` [Caml-list] " Jacques Garrigue
2008-01-18  2:28   ` Jacques Garrigue
2008-01-18  7:39   ` Till Varoquaux
2008-01-18  9:12     ` Jacques Garrigue
2008-01-18 16:55       ` Benjamin Canou
2008-01-18 17:05         ` Olivier Andrieu
2008-01-18 17:11           ` Jon Harrop
2008-01-18 17:43         ` Jon Harrop
2008-01-18 19:53           ` Benjamin Canou [this message]
2008-01-18 16:55       ` Edgar Friendly
2008-01-18 17:52         ` Kuba Ober
2008-01-18 17:56           ` Jon Harrop
2008-01-19  2:32         ` Jacques Garrigue
2008-01-24 22:52           ` Christophe Raffalli

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=1200685999.6345.40.camel@benjamin-laptop \
    --to=benjamin.canou@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=jon@ffconsultancy.com \
    /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