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 41B63BBAF for ; Wed, 19 Jul 2006 20:48:04 +0200 (CEST) Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.172]) by nez-perce.inria.fr (8.13.6/8.13.6) with ESMTP id k6JIm3nN000477 for ; Wed, 19 Jul 2006 20:48:04 +0200 Received: by ug-out-1314.google.com with SMTP id e2so463158ugf for ; Wed, 19 Jul 2006 11:48:03 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type; b=e7qewT6iyqUogMaQvQEebHzkeHkRrGiTSj+uPs6yrVnfZdD0ywBxQV4AeUftoopk9QqUBCVM7j3jqGXWGdJGHb6AxJROfqW5rs4GM1XPDM1RSzHcut/u+muXXpctmdIotSLP287T2KGU8kndEPxDCGNhl49VtWXQ4+ktUl4EmR8= Received: by 10.66.240.12 with SMTP id n12mr1063170ugh; Wed, 19 Jul 2006 11:48:03 -0700 (PDT) Received: by 10.67.122.6 with HTTP; Wed, 19 Jul 2006 11:48:03 -0700 (PDT) Message-ID: Date: Wed, 19 Jul 2006 14:48:03 -0400 From: "Jim Miller" To: caml-list@yquem.inria.fr Subject: Pattern matching question MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_44515_18885040.1153334883392" X-j-chkmail-Score: MSGID : 44BE7E63.000 on nez-perce : j-chkmail score : X : 0/20 1 X-Miltered: at nez-perce with ID 44BE7E63.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; ocaml:01 ocaml:01 specifies:01 specifies:01 W8:98 W12:98 W8:98 compile:01 compile:01 expression:01 expression:01 int:01 int:01 patterns:01 patterns:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.9 required=5.0 tests=DNS_FROM_RFC_ABUSE,HTML_20_30, HTML_MESSAGE,RCVD_BY_IP autolearn=disabled version=3.0.3 ------=_Part_44515_18885040.1153334883392 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline I'm trying to use an OCaml program to form an umambiguous protocol specification. I've convinced myself that by proper definition of my types, and avoiding using the _ in matches, I can get OCaml to help me verify that I have a complete specification. I'm doing this by defining a function that specifies the behavior of one of the protocol partners when it receives a message. Here is an example of what I have. let requestOp = REQUEST_KEY | SUCCESS;; let message = None | Register of requestOp * int;; 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) ;; The problem is with the final pattern in the inner match expression. I'm really trying to avoid using _ in patterns so that I'm forced to specify an action for each possible case (hence the reason I'm trying to use OCaml here). It appears that since I'm using a guard here that OCaml can't, at compile time, determine whether or not I'm being exhaustive. Is there a way to accomplish the same thing as above without using guards so that OCaml will be able to determine that my match is exhaustive? ------=_Part_44515_18885040.1153334883392 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline I'm trying to use an OCaml program to form an umambiguous protocol specification.  I've convinced myself that by proper definition of my types, and avoiding using the _ in matches, I can get OCaml to help me verify that I have a complete specification.  I'm doing this by defining a function that specifies the behavior of one of the protocol partners when it receives a message.  Here is an example of what I have.

let requestOp = REQUEST_KEY | SUCCESS;;

let message = None | Register of requestOp * int;;

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

The problem is with the final pattern in the inner match expression.  I'm really trying to avoid using _ in patterns so that I'm forced to specify an action for each possible case (hence the reason I'm trying to use OCaml here).    It appears that since I'm using a guard here that OCaml can't, at compile time, determine whether or not I'm being exhaustive.

Is there a way to accomplish the same thing as above without using guards so that OCaml will be able to determine that my match is exhaustive?

   
------=_Part_44515_18885040.1153334883392--