Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Alain Frisch <Alain.Frisch@inria.fr>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Snd question
Date: Wed, 17 Aug 2005 14:19:28 +0200	[thread overview]
Message-ID: <43032B50.40902@inria.fr> (raw)
In-Reply-To: <20050816181604.GA21719@furbychan.cocan.org>

Richard Jones wrote:
> On Tue, Aug 16, 2005 at 05:34:38PM +0100, Jon Harrop wrote:
> 
>>Currently, you cannot match [|1; ...|] in OCaml.
> 
> 
> Yes!  Or, "prefix" ^ str.

This seems like a good place to insert a shameless plug. Thank you. In 
OCamlDuce (the extension of OCaml with XML types and patterns), you can 
indeed match on string prefixes:

# type t = {{ "OCaml" | "OCamlDuce" | "Other" }};;
type t = {{t}}
# fun (x : t) -> match x with {{ [ 'O' x::PCDATA ] }} -> x;;
- : {{t}} -> {{[ 'ther' | 'Caml' | 'CamlDuce' ]}} = <fun>

You can actually match on more complex regular expressions. E.g., to 
extract all the uppercase ASCII characters:

# fun (x : t) -> match x with {{ [ (x::'A'--'Z' | _)* ] }} -> x;;
- : {{t}} -> {{[ 'OC' | 'OCD' | 'O' ]}} = <fun>

or to split a string:

# let f (x : {{String}}) : {{String}} * {{String}} =
   match x with {{ [ x::PCDATA '.' y::PCDATA ] }} -> (x,y)
              | {{_}} -> raise Not_found;;
val f : {{String}} -> {{String}} * {{String}} = <fun>



-- Alain


  parent reply	other threads:[~2005-08-17 12:19 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-15 22:05 Anu Engineer
2005-08-15 22:41 ` [Caml-list] " Matt Gushee
2005-08-16  8:08   ` sejourne kevin
2005-08-16 13:17   ` skaller
2005-08-16 16:16     ` Julian Brown
2005-08-16 17:18       ` [Caml-list] " Alan Falloon
2005-08-17  6:15       ` skaller
2005-08-16 16:34     ` [Caml-list] " Jon Harrop
2005-08-16 18:16       ` Richard Jones
2005-08-16 21:42         ` Jon Harrop
2005-08-17  6:55           ` skaller
2005-08-18  8:20             ` Andrej Bauer
2005-08-18 17:51               ` skaller
2005-08-19  7:50                 ` Andrej Bauer
2005-08-17 12:19         ` Alain Frisch [this message]
2005-08-17 17:21           ` skaller
2005-08-17 23:08           ` Martin Jambon
2005-08-17  6:28       ` skaller
2005-08-20 14:31     ` Brian Hurt

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=43032B50.40902@inria.fr \
    --to=alain.frisch@inria.fr \
    --cc=caml-list@yquem.inria.fr \
    /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