caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] pattern matching on strings
@ 2011-09-14 20:16 Walter Cazzola
  2011-09-14 20:40 ` Basile Starynkevitch
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Walter Cazzola @ 2011-09-14 20:16 UTC (permalink / raw)
  To: OCaML Mailing List

[-- Attachment #1: Type: TEXT/PLAIN, Size: 665 bytes --]

Hi all,
I'm just trying to write a recursive function that iterates¹ on a string
and I'd like to use pattern matching as in:

let rec iter f s =
   match s with
      | ""  -> unit;
      | c^s1 -> f c; iter f s1;;

but the ^ concatenates 2 strings and not a char with a string and above
all seems to be inadmissible in the patterns.

Does this mean that I can't write a function on strings by pattern
matching or is there something I don't know?²

Thanks for the help
Walter

¹ I know that exists String.iter but I'd like to improve my skill in
   writing functions by using pattern matching
² I read about micmatch but I'd like to avoid non standard packages.
-- 

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-09-17  8:16 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-14 20:16 [Caml-list] pattern matching on strings Walter Cazzola
2011-09-14 20:40 ` Basile Starynkevitch
2011-09-16 21:20   ` Richard W.M. Jones
2011-09-17  8:15     ` Basile Starynkevitch
2011-09-14 20:57 ` Philippe Veber
2011-09-14 21:44   ` Raphael Proust
2011-09-16 22:18     ` Philippe Veber
2011-09-14 21:14 ` Philippe Strauss

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).