Version française
Home     About     Download     Resources     Contact us    
Browse thread
Pattern matching question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jim Miller <gordon.j.miller@g...>
Subject: Pattern matching question
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?