caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Christophe Raffalli <raffalli@cs.chalmers.se>
To: Pierre.Weis@inria.fr
Cc: caml-list@pauillac.inria.fr
Subject: Re: Suggestions
Date: Wed, 13 Sep 1995 18:51:38 +0200	[thread overview]
Message-ID: <199509131651.SAA24277@waldorf.cs.chalmers.se> (raw)
In-Reply-To: <199509131511.RAA29007@pauillac.inria.fr> (message from Pierre Weis on Wed, 13 Sep 1995 17:11:31 +0200 (MET DST))


> Why don't you use the ``when'' clauses of Caml Light 0.7?
>
> let f x =
>   match read x with
>    C (x1, x2) when
>     (match read x1, read x2 with
>        C _,C _ -> true
>      | _ -> false) ->
>      ...code2...
>  | _ -> ...code1...
>;;

This is ok in this example, but the problem is that "when" is not a binder !

So if I want to write 

let f x =
  match read x with
    C (x1, x2) when
     (match read x1, read x2 with
        C (x3,x4),C (x5,x6) -> true
      | _ -> false) ->
      ...code2...
  | _ -> ...code1...
;;

x3,x4,x5,x6 are not bound in ...code2... too bad !

With the "where match" match guard it will work and look nicer !

let f x =
  match read x with
    C (x1, x2) where
      match read x1, read x2 with
        C (x3,x4),C (x5,x6) -> ....code2....
  | _ -> ...code1...
;;

The "where match" is in fact strictly more general than the when:

   pat when exp ->

is equivalent to

   pat where match exp with true ->

but the when is weaker because it does not bind any variable.


Christophe Raffalli.





  reply	other threads:[~1995-09-13 17:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-09-12  9:27 Release 1.06 of Caml Special Light Xavier Leroy
1995-09-13  8:15 ` Suggestions Christophe Raffalli
1995-09-13 15:11   ` Suggestions Pierre Weis
1995-09-13 16:51     ` Christophe Raffalli [this message]
1995-09-14  9:49       ` Suggestions Pierre Weis
1999-01-27  1:18 Suggestions Miles Egan
1999-01-27 18:48 ` Suggestions Jon Moore
1999-01-28 10:50   ` Suggestions Xavier Leroy

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=199509131651.SAA24277@waldorf.cs.chalmers.se \
    --to=raffalli@cs.chalmers.se \
    --cc=Pierre.Weis@inria.fr \
    --cc=caml-list@pauillac.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;
as well as URLs for NNTP newsgroup(s).