Version française
Home     About     Download     Resources     Contact us    
Browse thread
Strange performances
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jon Harrop <jon@f...>
Subject: Re: [Caml-list] Strange performances
On Friday 18 January 2008 16:55:14 Benjamin Canou wrote:
> This code works perfectly :
>
> let list_of_string s =
>   let rec list_of_string s i =
>     try let e = s.[i] in e :: list_of_string s (succ i)
>     with Invalid_argument "index out of bounds" -> []
>   in list_of_string s 0

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;;

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/products/?e