caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Pierre Weis <weis@pauillac.inria.fr>
To: Julian Assange <proff@iq.org>
Cc: caml-list@pauillac.inria.fr
Subject: Re: let ... in layout
Date: Fri, 17 Mar 2000 10:42:15 +0100	[thread overview]
Message-ID: <20000317104215.56763@pauillac.inria.fr> (raw)
In-Reply-To: <wxvh2nyj1f.fsf@suburbia.net>; from Julian Assange on Thu, Mar 16, 2000 at 09:18:04AM +1100

> Jean-Yves Moyen <Jean-Yves.Moyen@loria.fr> writes:
> 
> > let f a b c=
> >   match a,b,c with
> >     ...
> > 
> > which allows you to match several arguments at once.
> 
> Sure, but
> 
> let f a b c =
>    match a,b,c with
>         0,1,2 -> 3
> 
> is a lot more cluttered than
> 
> f 0 1 2 = 3
> 
> This wouldn't really be an issue except that pattern matching is so
> common. Intuitive brevity (as opposed to the brevity represented by
> languages such as perl) is what makes both haskell and *ml so
> readable. While both functions seem equally readable because they are
> both small, once you have a screen full of them there is a significant
> difference in clarity.
> 
> Cheers,
> Julian.

You're right but this is not only a problem of syntax. There are
semantics issues to consider.

As for the syntax, your example is a bit contrieved, since there are
not that many functions with pattern matching on 3 arguments that has
only one match case. In general, such a complex function will have
many cases and then the (admittedly heavier) way of writing the code
in Caml gives you an extra benefit of naming the arguments, not
repeating the function name, and clearly exhibit the complete pattern
matching in one place:

let f a b c =
    match a, b, c with
    | 0, _, 0 -> a + b + c
    | ....

Also, the semantics of partial applications of curried pattern
matching is not clear: consider your f example

let f 0 1 2 = 3;;

What's the meaning of this definition ? Two interpretations have been
used in Caml:

let f1 a b c =
    match a, b, c with
    | 0, 1, 2 -> 3
    | _ -> raise Match_failure

let f2 = function
  | 0 -> (function
          | 1 -> (function
                  | 2 -> 3
                  | _ -> raise Match_failure)
          | _ -> raise Match_Failure)
  | _ -> raise Match_Failure

I guess f2 is more consistent with the usual semantics of ML, while f1
seems to be more natural for users:

with f2 partial applications will fail as early as necessary:
(f 1 raises Match_failure as the definition of g in let g = List.map (f 1)),

while with f1, application of f will fail only when 3 arguments are provided.

I guess that this is this semantic problem, and the new syntax to add
that prevents the addition of this feature to Caml.

Best regards,

Pierre Weis

INRIA, Projet Cristal, http://pauillac.inria.fr/~weis



  reply	other threads:[~2000-03-17 10:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-03-15  1:33 Julian Assange
2000-03-15  8:22 ` Jean-Yves Moyen
2000-03-15 22:18   ` Julian Assange
2000-03-17  9:42     ` Pierre Weis [this message]
2000-03-15  8:56 ` Benoit Deboursetty
2000-03-17 13:16 ` Dmitri Lomov

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=20000317104215.56763@pauillac.inria.fr \
    --to=weis@pauillac.inria.fr \
    --cc=caml-list@pauillac.inria.fr \
    --cc=proff@iq.org \
    /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).