Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: Luc Maranget <luc.maranget@i...>
Subject: Re: [Caml-list] Pattern matching
About pattern matching.
> 
> "Diego Olivier Fernandez Pons" <FernandezPons@iFrance.com> 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
means).



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.


--Luc

-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr