caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Brian Rogoff <bpr@best.com>
To: Miles Egan <miles@caddr.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] printable digest strings
Date: Fri, 4 May 2001 07:50:04 -0700 (PDT)	[thread overview]
Message-ID: <Pine.BSF.4.21.0105040732150.25671-100000@shell5.ba.best.com> (raw)
In-Reply-To: <20010504070014.A35277@caddr.com>

On Fri, 4 May 2001, Miles Egan wrote:
> This actually brings me to my next question.  There doesn't seem to be a
> String.map or String.iter function in the standard library, although I can
> imagine they might also be handy.  Am I looking in the wrong place?

Nope, they're not there. You could use the compiler source, and steal the
corresponding functions from arrays, since OCaml does the right thing and 
has array-like strings (as opposed to say, Erlang and Haskell). Here's the 
touch up for those two

let iter f s =
  for i = 0 to String.length s - 1 do f(String.unsafe_get s i) done

let map f s =
  let l = String.length s in
  if l = 0 then "" else begin
    let r = String.create l in
    for i = 1 to l - 1 do
      String.unsafe_set r i (f(String.unsafe_get s i))
    done;
    r
  end

You can now (OCaml 3.01) make your own String module with these functions
and include the native String module to get what you want. 

This is another one of those cases where some overloading might be nice,
since IMO there is not much point in distinguishing all of the different 
kinds of random access with .[], .(), .{}. 

-- Brian


-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


  reply	other threads:[~2001-05-04 14:50 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-05-03 22:32 Miles Egan
2001-05-04  9:15 ` Hendrik Tews
2001-05-04  9:37 ` Xavier Leroy
2001-05-04 14:00   ` Miles Egan
2001-05-04 14:50     ` Brian Rogoff [this message]
2001-05-04 20:27   ` Chris Hecker
2001-05-04 22:54     ` Miles Egan
2001-05-06 18:56     ` [Caml-list] Wserver: Values of global variables lost Mattias Waldau
2001-05-07  8:58       ` Daniel de Rauglaudre
2001-05-07 17:00       ` Mattias Waldau
2001-05-07 18:16         ` Daniel de Rauglaudre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.BSF.4.21.0105040732150.25671-100000@shell5.ba.best.com \
    --to=bpr@best.com \
    --cc=caml-list@inria.fr \
    --cc=miles@caddr.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).