caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Ben Millwood <bmillwood@janestreet.com>
To: Goswin von Brederlow <goswin-v-b@web.de>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Proposal: extend try to handle success
Date: Thu, 6 Feb 2014 11:10:21 +0000	[thread overview]
Message-ID: <CA+MHO51M-kdY+JA9D0ryKMq_Gz=_EyFjc=10ope_M_1de1hCfQ@mail.gmail.com> (raw)
In-Reply-To: <20140206105811.GD28534@frosties>

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

On 6 February 2014 10:58, Goswin von Brederlow <goswin-v-b@web.de> wrote:

> How do you match any exception but not a successfull value?
>
> let f5 x =
>   try None
>   with
>   | Empty -> ()
>   | val x -> x
>   | _ -> 1
>
> Or does "_" only match exceptions and "val _" any value?
>

Interesting.

So, I would assume that the behaviour of _ would be unchanged, so it would
match any exception and no value in a try and any value and no exception in
a match.

The way I justify this is that "val x" or "exception x" aren't really
patterns, but rather "x" is a pattern and val/exception are part of the
try/match syntax. For example, "val (val x)" would presumably be a parse
error. As such, "_" isn't a more general pattern than "val _", because
they're different kinds of thing.

This makes me wonder if the current syntax is misleadingly uniform. Perhaps
value and exception cases ought to be more clearly separated, e.g.

try (...)
with val
| Some x -> (...)
| None -> (...)
with exception
| Not_found -> (...)

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

  reply	other threads:[~2014-02-06 11:10 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-04 17:00 Jeremy Yallop
2014-02-04 17:14 ` Simon Cruanes
2014-02-04 18:09   ` Jeremy Yallop
2014-02-04 19:05     ` Gabriel Scherer
2014-02-04 19:18 ` Markus Mottl
2014-02-04 19:29   ` Markus Mottl
2014-02-04 19:42     ` Yaron Minsky
2014-02-05 16:04       ` Jesper Louis Andersen
2014-02-06 10:58 ` Goswin von Brederlow
2014-02-06 11:10   ` Ben Millwood [this message]
2014-02-10  8:47     ` Goswin von Brederlow
2014-02-10  9:23       ` Ben Millwood
2014-02-10 14:39         ` Alain Frisch
2014-02-06 11:36   ` Jeremy Yallop

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='CA+MHO51M-kdY+JA9D0ryKMq_Gz=_EyFjc=10ope_M_1de1hCfQ@mail.gmail.com' \
    --to=bmillwood@janestreet.com \
    --cc=caml-list@inria.fr \
    --cc=goswin-v-b@web.de \
    /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).