caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Jim Miller" <gordon.j.miller@gmail.com>
To: caml-list@yquem.inria.fr
Subject: Pattern matching question
Date: Wed, 19 Jul 2006 14:48:03 -0400	[thread overview]
Message-ID: <beed19130607191148k4d94b706mf1f7ce222b1d7fba@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1311 bytes --]

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?

[-- Attachment #2: Type: text/html, Size: 1706 bytes --]

             reply	other threads:[~2006-07-19 18:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-19 18:48 Jim Miller [this message]
2006-07-19 18:55 ` [Caml-list] " Seth J. Fogarty
     [not found] ` <ad8cfe7e0607191737l551e1d8aif8d5859fb6c398fd@mail.gmail.com>
2006-07-20  1:03   ` Jim Miller
2006-07-20  8:38 ` 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=beed19130607191148k4d94b706mf1f7ce222b1d7fba@mail.gmail.com \
    --to=gordon.j.miller@gmail.com \
    --cc=caml-list@yquem.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).