Browse thread
anonymous function + lable bug?
-
Chris Hecker
-
Jacques Garrigue
-
Chris Hecker
- Jacques Garrigue
-
Chris Hecker
- Sven LUTHER
-
Jacques Garrigue
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| 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? Exactly. > 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