Browse thread
Fwd: Re: [Caml-list] The boon of static type checking
[
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: | William D.Neumann <wneumann@c...> |
| Subject: | Re: [Caml-list] String to list to string |
On Feb 9, 2005, at 7:10 PM, Juancarlo Añez wrote: > Why aren't there functions in the standard library to convert strings > to > lists of characters and back? Because a) they're not all that useful and b) they're trivial to write for yourself: let explode s = let rec exh acc = function | -1 -> acc | i -> exh (s.[i]::acc) (pred i) in exh [] (pred (String.length s)) let implode l = let s = String.create (List.length l) in let rec imh i = function | h::t -> s.[i] <- h; imh (succ i) t | [] -> s in imh 0 l William D. Neumann "You've got Rita Marlowe in the palm of your hand." "Palm of my hand? You haven't seen Rita Marlowe..." -- Will Success Spoil Rock Hunter?