Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] New to OCaml: can someone explain how this code can be done better?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Stefano Zacchiroli <zack@c...>
Subject: Re: [Caml-list] New to OCaml: can someone explain how this code can be done better?
On Sat, Jun 23, 2001 at 03:39:19PM -0400, Eric C. Cooper wrote:
>    characters.  As you'll see, the only imperative code is in this
>    conversion step; the rest is purely functional.
:-((

let rec explode_string = function
   "" -> []
 | s -> (String.get s 0) :: explode_string (String.sub s 1 (String.length s - 1))
;;
let rec implode_string = function
   [] -> ""
 | h::t -> (String.make 1 h) ^ implode_string t
;;

Sorry, I can't resist :-)

Cheers.

-- 
Stefano "Zack" Zacchiroli <zack@cs.unibo.it> ICQ# 33538863
Home Page: http://www.students.cs.unibo.it/~zacchiro
Undergraduate student of Computer Science @ University of Bologna, Italy
	                - Information wants to be Open -
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr