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 E5409BB83 for ; Wed, 19 Jul 2006 20:55:15 +0200 (CEST) Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.186]) by nez-perce.inria.fr (8.13.6/8.13.6) with ESMTP id k6JItFTr001549 for ; Wed, 19 Jul 2006 20:55:15 +0200 Received: by nf-out-0910.google.com with SMTP id g2so304680nfe for ; Wed, 19 Jul 2006 11:55:15 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=MuCtV7IuCfmf7TAHW7h7aM3d7nz092XMc++4RrjC7576CKYikZa7x10gQnGbf/BViurNu4H6hY8I+XCVv7yFvwrt0JokFtkuyfL/+BTL9RhInxjh0+ZPbTvfdvpJ2q9qxifajfW7SI8TaT8X+bT8RaIkmnzMb2qkH95Xn0QYkFg= Received: by 10.78.156.6 with SMTP id d6mr647259hue; Wed, 19 Jul 2006 11:55:14 -0700 (PDT) Received: by 10.78.150.5 with HTTP; Wed, 19 Jul 2006 11:55:14 -0700 (PDT) Message-ID: Date: Wed, 19 Jul 2006 13:55:14 -0500 From: "Seth J. Fogarty" Subject: Re: [Caml-list] Pattern matching question Cc: caml-list@yquem.inria.fr In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: X-j-chkmail-Score: MSGID : 44BE8013.001 on nez-perce : j-chkmail score : X : 0/20 1 X-Miltered: at nez-perce with ID 44BE8013.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; ocaml:01 ocaml:01 specifies:01 foo:01 wrote:01 caml-list:01 int:01 defining:02 match:02 match:02 types:02 pattern:03 let:03 let:03 avoiding:03 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=DNS_FROM_RFC_ABUSE,RCVD_BY_IP autolearn=disabled version=3.0.3 On 7/19/06, Jim Miller wrote: > 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) > ;; Try something like match idList with [] -> Register(SUCCESS, id) | l -> if List.mem id l then Register(foo) else Register(bar) And replace the guard with an if statement. -- Seth Fogarty sfogarty@[gmail.com|rice.edu|livejournal] Neep-neep at large AIM: Sorrath "I know there are people in this world who do not love their fellow human beings - and I hate people like that" --Tom Lehrer.