caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Seth J. Fogarty" <sfogarty@gmail.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Pattern matching question
Date: Wed, 19 Jul 2006 13:55:14 -0500	[thread overview]
Message-ID: <c7ee61120607191155x736150c2m98e3a15549928d7a@mail.gmail.com> (raw)
In-Reply-To: <beed19130607191148k4d94b706mf1f7ce222b1d7fba@mail.gmail.com>

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.


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

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