caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jon Harrop <postmaster@jdh30.plus.com>
To: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Pattern matching over elements at the front of a container
Date: Mon, 28 Jun 2004 13:01:00 +0100	[thread overview]
Message-ID: <200406281301.01048.postmaster@jdh30.plus.com> (raw)
In-Reply-To: <20040628095709.B17827@beaune.inria.fr>

On Monday 28 June 2004 08:57, Luc Maranget wrote:
> > In the case of lists, you can match against the first two elements using
> > the pattern "a::b::_". As the "_" is not bound in the corresponding
> > expression, an equivalent notation could be invented for arrays in this
> > case. Is this feasible? Would anyone else find this useful?
>
> It is certainly feasible, whether it is worth including in the compiler is
> debatable...

Yes, I can see what William Lovas meant about these being "ad-hoc" forms of 
pattern matching. These ideas came up while I was writing an interpreter for 
a host language which supports very exotic pattern matching. However, its 
pattern matcher has an unspecified (and often very high!) complexity, so 
apparently simple pieces of code fail to terminate on reasonable input before 
my patience runs out. This is clearly undesirable.

I thought my idea of using something like [|h1; h2; ..|] was rather nice, 
because it works in finite time in the limit of infinite input-array size, 
but it is ad-hoc: why not [|..; h2; h1|] then?

I suppose list decapitation "h1::h2::t" marks the limit in the usefulness vs 
difficulty tradeoff. Internally, I guess list matching is also based upon 
data structure's shape, whereas my [|h; ..|] and Richard Jones' "prefix"^str 
are not, because the data structures are both arrays which are "atomic" in 
this sense.

> > Also, is it not possible to alter the definition and implementation of
> > OCaml such that the pattern "(a, a)" is treated as "(a, b) when a=b"? Has
> > this not been done because the "=" is suspect?
>
> Just say No (to non-linear patterns) !

Can you define "non-linear pattern" for me?

> Basically and you can interpret this by saying << = is suspect >>, this
> apparently innocent addition is a radical change in semantics.

Mikael Brockman wrote to me, pointing out that matching this could use "the 
same unification algorithm as is used in other pattern matching" which sounds 
like a much better interpretation of the equality to me. Is that not correct 
because patterns can only contain constant values and cannot be matched 
against arbitrary values, like expressions or variables? So the pattern 
matcher does not currently require any notion of equality beyond those of 
constructors and of values of primitive types?

Cheers,
Jon.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  reply	other threads:[~2004-06-28 12:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-26 11:15 Jon Harrop
2004-06-26 13:36 ` skaller
2004-06-27 10:11 ` Richard Jones
2004-06-27 11:40   ` William Lovas
2004-06-28  7:57 ` Luc Maranget
2004-06-28 12:01   ` Jon Harrop [this message]
2004-06-28 12:50     ` Luc Maranget
2004-06-28 17:09       ` Jon Harrop

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=200406281301.01048.postmaster@jdh30.plus.com \
    --to=postmaster@jdh30.plus.com \
    --cc=caml-list@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).