[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Seth J. Fogarty <sfogarty@g...> |
| Subject: | Re: [Caml-list] Pattern matching question |
On 7/19/06, Jim Miller <gordon.j.miller@gmail.com> 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.