Browse thread
Strange performances
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Benjamin Canou <benjamin.canou@g...> |
| Subject: | Re: [Caml-list] Strange performances |
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.