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
anonymous function + lable bug?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2000-11-08 (17:35)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: anonymous function + lable bug?
From: Chris Hecker <checker@d6.com>

> >> I thought these two were equivalent?
> >They are not:
> Right, I didn't mean to say they're completely equivalent (I've read
> the FAQ), just that I expected equivalence in that case.
> >It would be possible to add special rules to allow
> >        function ~l:p1 -> e1 | ... | ~l:pn -> en
> Ah, now I see, it's because the parameter in function is actually
> the pattern in an implicit match?


> Is there ever a reason to use function (assuming you don't mind
> parenthesizing constructors and whatnot in fun arguments)?  Does the
> implied match allow some simplification or optimization or
> something?  Why do they both exist?

function is not necessary: you can replace it everywhere with fun and
match, and the code is exactly optimized the same way. Actually some
pass of the compiler expands function in fun+match.

However, in many cases function is a nice and intuitive short-hand for
directly matching on an argument. The reason for it to be here seems
mostly historical: one can define let in terms of fun (+ special
typing), and match in terms of function (no special typing
required). As I remember it, SML (/NJ?) was actually seeing case
(=match) as syntactic sugar for fn(=function).

Jacques Garrigue