From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA20045 for caml-red; Fri, 28 Jul 2000 15:16:28 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id DAA12612 for ; Fri, 28 Jul 2000 03:18:48 +0200 (MET DST) Received: from dopamine.iq.org (dopamine.iq.org [203.4.184.129]) by nez-perce.inria.fr (8.10.0/8.10.0) with ESMTP id e6S1IeL05581 for ; Fri, 28 Jul 2000 03:18:45 +0200 (MET DST) Received: by dopamine.iq.org (Postfix, from userid 110) id B8C7310F3B; Thu, 27 Jul 2000 00:13:24 +1000 (EST) To: caml-list@inria.fr Subject: addressable_to_list Cc: proff@iq.org From: Julian Assange Date: 27 Jul 2000 00:13:24 +1000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: weis@pauillac.inria.fr The following ocaml function converts a string to a list: (which btw, I guess should be in the String module) let string_to_list s = let len = String.length s in let rec scan n = if n < len then s.[n] :: scan (n + 1) else [] in scan len However, what I'd like to be able to do this for any countable thing. e.g let nthable_to_list s fnth flen = let len = flen s in let rec scan n = if n < len then fnth s n :: scan (n + 1) else [] in scan len Then one can of course simulate the first code snippit with: let string_of_list s = nthable_to_list s (fun s n -> s.[n]) (fun s -> String.length s) I know how this is done in Haskell, but how do something like it in O'caml? A couple of useful string functions that are missing: conversion, strings <-> bigarrays of chars a bigarry like create function, which takes a function argument. (regular Array's also have the same problem). String has functions to create an empty, constant filled string, or an uninitialised string. This is pretty important, because Digest for instance, only takes strings. While I'm on the subject of array initialisers, the new safe array creation could be improved. From memory, it takes a function which takes an int and returns an initialisation element. It would be better if the counting was left upto the user supplied function and the output was fed back into the input. e.g like foldr. e.g ('a -> 'b * 'a) -> 'b array 1.. initialisation would then look like (fun x -> x, x+1) Cheers, Julian.