From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 5D258BB83 for ; Thu, 20 Jul 2006 03:03:12 +0200 (CEST) Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.173]) by nez-perce.inria.fr (8.13.6/8.13.6) with ESMTP id k6K13BkW025278 for ; Thu, 20 Jul 2006 03:03:12 +0200 Received: by ug-out-1314.google.com with SMTP id e2so592335ugf for ; Wed, 19 Jul 2006 18:03:11 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=G6i656vKy+thraJ08sOLumYL5NrH4Fce0UdzmaAhkNLFcRqBQI4fy6nx4iE3ZfIFeGbRrCRxkuyTttBqkSVsXUEWf/vI1iIJAFCzES4e85LPlEju9gGqNvJVc8xs36rYRLUYnFZIy23Nn4zIa+HW5gOeKF0wHD659qR52sRwkno= Received: by 10.67.93.6 with SMTP id v6mr1326243ugl; Wed, 19 Jul 2006 18:03:11 -0700 (PDT) Received: by 10.67.122.6 with HTTP; Wed, 19 Jul 2006 18:03:11 -0700 (PDT) Message-ID: Date: Wed, 19 Jul 2006 21:03:11 -0400 From: "Jim Miller" To: "Jonathan Roewen" , caml-list@yquem.inria.fr Subject: Re: [Caml-list] Pattern matching question In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_47356_6655865.1153357391616" References: X-j-chkmail-Score: MSGID : 44BED64F.001 on nez-perce : j-chkmail score : X : 0/20 1 X-Miltered: at nez-perce with ID 44BED64F.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; syntax:01 syntax:01 W6:98 W10:98 W14:98 W10:98 W6:98 wrote:01 wrote:01 caml-list:01 constructor:01 constructor:01 defined:02 defined:02 match:02 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: ** X-Spam-Status: No, score=2.3 required=5.0 tests=DNS_FROM_RFC_ABUSE,HTML_40_50, HTML_MESSAGE,RCVD_BY_IP,RCVD_IN_BL_SPAMCOP_NET autolearn=disabled version=3.0.3 ------=_Part_47356_6655865.1153357391616 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 7/19/06, Jonathan Roewen wrote: > > > let receive idList msg = > > match message with > > None -> None > > > > | Register( REQUEST_KEY, id ) -> begin > > match idList with > > [] -> Register(SUCCESS, id) > > | l when (List.mem id l) -> Register(Success, > (next_available_id > > l)) > > | _ -> Register(Success, id) > > ;; > > For the inner match, why you even both with it is beyond me. All you > are doing is wrapping List.mem in an unnecessary test. > > It should be: > | Register(REQUEST_KEY,id) -> > if List.mem id idList then > Register(Success, next_available_id l) > else > Register(Success, id) > > Perhaps the fact that your example makes no sense (it's not a complete > definition, nor is Success defined anywhere, nor does Register even > accept the constructor Success) doesn't help here. The main purpose is not to actually construct a program but to construct a specification of a communications protocol in a syntax that I can give to a non-coder and have them read but also have some validation that I'm checking all possible cases. You are correct in your statement that the match isn't necessary but that's assuming that I care about the program. The match is much more explicit to a non-coder (at least that's the feedback I've gotten) of the case that we''re trying to test. ------=_Part_47356_6655865.1153357391616 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 7/19/06, Jonathan Roewen <jonathan.roewen@gmail.com> wrote:
> let receive idList msg =
>   match message with
>      None -> None
>
> |    Register( REQUEST_KEY, id ) -> begin
>          match idList with
>              [] -> Register(SUCCESS, id)
>          |   l when (List.mem id l) -> Register(Success, (next_available_id
> l))
>          |  _ -> Register(Success, id)
> ;;

For the inner match, why you even both with it is beyond me. All you
are doing is wrapping List.mem in an unnecessary test.

It should be:
| Register(REQUEST_KEY,id) ->
   if List.mem id idList then
      Register(Success, next_available_id l)
   else
      Register(Success, id)

Perhaps the fact that your example makes no sense (it's not a complete
definition, nor is Success defined anywhere, nor does Register even
accept the constructor Success) doesn't help here.


The main purpose is not to actually construct a program but to construct a specification of a communications protocol in a syntax that I can give to a non-coder and have them read but also have some validation that I'm checking all possible cases.

You are correct in your statement that the match isn't necessary but that's assuming that I care about the program.  The match is much more explicit to a non-coder (at least that's the feedback I've gotten) of the case that we''re trying to test.


------=_Part_47356_6655865.1153357391616--