caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Pattern matching question
@ 2006-07-19 18:48 Jim Miller
  2006-07-19 18:55 ` [Caml-list] " Seth J. Fogarty
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jim Miller @ 2006-07-19 18:48 UTC (permalink / raw)
  To: caml-list

[-- 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 --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-07-20  8:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-19 18:48 Pattern matching question Jim Miller
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

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