English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Patterns that evaluate
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-02-14 (19:10)
From: Denis Bueno <dbueno@g...>
Subject: Re: [Caml-list] Patterns that evaluate
On 2/14/07, Gerd Stolpmann <info@gerd-stolpmann.de> wrote:
> You are a bit quick. Before discussing syntax it is more important to
> define the semantics of such patterns. I mean we have already three
> predefined kinds of equality in O'Caml:
> - ( == )
> - ( = )
> - (fun x y -> compare x y = 0)
> I admit I do not prefer any one of them. So which equality should be
> used to test whether the variable is equal to the matched part of the
> value?
> I guess this simple question is one of the reasons why such a feature is
> not in the language up to now.

I agree with Gerd: equality is a hard thing to get right.

For many months now I have been working on a compiler for a constraint
solving language, and I always need to spend a significant amount of
time, after the creation of each data structure, defining comparisons
on instances of those structures. Usually there is one that defines an
ordering for the purpose of using instances as keys in a Map; and
sometimes there are additional equivalence relations that compare
different aspects of structures.

The principle then, applied to this problem, is: immediately *someone*
is going to need a comparison function other than the ones above. And
if there is no support for such functions, many people will consider
the feature useless for all but the simplest of tasks. If there is
support, it will become a question of just how convenient that support

These aren't necessarily un-answerable questions; but they are not easy.