Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Re: [Caml-list] Pattern matching
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-11-09 (10:59)
From: Luc Maranget <luc.maranget@i...>
Subject: Re: [Caml-list] Pattern matching
About pattern matching.
> "Diego Olivier Fernandez Pons" <> writes:
is right to stress on the fact that variables in patterns are
binding variables, some variable is bound to something.
when you write

let x = ex in
let x = ex' in

You certainly do not mean that ex and ex' are equal (whatever it

On linearity :

> > let egalite = function
> >    | (x,x) -> true
> >    | (x,y) -> false
> > ;;
> > # This variable is bound several times in this matching
> i wonder why this one is not allowed since it can't have any other meaning
> than the one it has in prolog. What's the reason for not having it rewritten
> to:

Does not mean :

> > let egalite = function
> >    | (x,x') when x=x' -> true
> >    | (x,y) -> false

Well, it could be that way. But it is not.

This can be argueed as follows.

  As already said the meaning of (x,x) is not clear, should we use
  ``='' (and then pattern matching may last for ever, or may raise
  an exception (for functions)) or ``=='' (and this is not very useful).

  Futhermore the theory of non-left-linear rewriting is more
  complicated than the one of left-linear rewriting and this theory
  somehow applies to ML pattern matching.

So my opinion is that non-linear pattern brings little benefits to
users, complicates much the life of the compiler writer and may even
introduce subtle bugs in users programs.


Bug reports:  FAQ:
To unsubscribe, mail  Archives: