caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: Martin Jambon <martin_jambon@emailuser.net>
Cc: Luc Maranget <luc.maranget@inria.fr>,
	Christophe Raffalli <christophe.raffalli@univ-savoie.fr>,
	sejourne_kevin <sejourne_kevin@yahoo.fr>,
	caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Request for complete pattern matching
Date: Thu, 24 Nov 2005 08:30:04 +1100	[thread overview]
Message-ID: <1132781404.25948.78.camel@rosella> (raw)
In-Reply-To: <Pine.LNX.4.63.0511231120410.3572@munge>

On Wed, 2005-11-23 at 12:56 -0800, Martin Jambon wrote:

> (* toto.ml *)
> try
>    while true do
>      match read_line () with
>  	/ upper / | / _* "." eos / -> print_endline "looks like a sentence"
>        | "." | / ("bye"~ space*)+ / -> print_endline "Bye!"; exit 0
>        | _ -> print_endline "???"
>    done
> with End_of_file -> ()
> 
> Notes:
> - the stuff between slashes are regexps
> - "." and the last _ are regular OCaml patterns
> - regexps are replaced by an identifier which is matched after the 
> arrow using library functions, then it is decided whether to jump to the 
> next case or to execute the user-given expression.

Why can't this be done with 'when' clause?

EG:

	| ... predicate ... -> ...

replace by 

	| ... variable .. when predicate(variable)

This would seem to fail only in that 'predicate' code
cannot refer to another predicate, since the variable
name is not known.

The 'break' implementation, however, may be overtly
more efficient (save duplicating predicate evaluations).

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


  reply	other threads:[~2005-11-23 21:30 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-22 22:43 Christophe Raffalli
2005-11-23  5:54 ` [Caml-list] " Luc Maranget
2005-11-23 14:37   ` Christophe Raffalli
2005-11-23 10:06 ` Michal Moskal
2005-11-23 15:26   ` Christophe Raffalli
     [not found] ` <43842069.3070700@yahoo.fr>
2005-11-23 14:47   ` Christophe Raffalli
2005-11-23 18:31     ` Luc Maranget
2005-11-23 20:56       ` Martin Jambon
2005-11-23 21:30         ` skaller [this message]
2005-11-23 22:25           ` Martin Jambon
2005-11-24  9:29         ` Luc Maranget
2005-11-25 23:01           ` Martin Jambon
2005-11-23 20:56       ` Christophe Raffalli
2005-11-24  9:41         ` Luc Maranget

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=1132781404.25948.78.camel@rosella \
    --to=skaller@users.sourceforge.net \
    --cc=caml-list@inria.fr \
    --cc=christophe.raffalli@univ-savoie.fr \
    --cc=luc.maranget@inria.fr \
    --cc=martin_jambon@emailuser.net \
    --cc=sejourne_kevin@yahoo.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;
as well as URLs for NNTP newsgroup(s).