[
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: | 2000-11-08 (16:24) |
From: | Jacques Garrigue <garrigue@k...> |
Subject: | Re: anonymous function + lable bug? |
From: Chris Hecker <checker@d6.com> > Is this a bug? > > # let f = fun ~x -> x;; > val f : x:'a -> 'a = <fun> > > # let g = function ~x -> x;; > Characters 17-18: > Syntax error > > I thought these two were equivalent? They are not: Similar to the above example, # let f = fun x y -> x;; val f : 'a -> 'b -> 'a = <fun> # let f = function x y -> x;; Syntax error ^ and the other way round, # let f = fun Some x -> x;; ^^^^ The constructor Some expects 1 argument(s), but is here applied to 0 argument(s) # let f = function Some x -> x;; val f : 'a option -> 'a = <fun> The equivalence (in the no-label case) is between function p1 -> e1 | ... | pn -> en and fun x -> match x with p1 -> e1 | ... | pn -> en fun and function only become equivalent when the matching is trivial, and there is no need to use an explicit match ... with This is a true equivalence: the compiled code is identical, so you can really think of function as a shorthand for the explicit form with match, when you take only a single non-labelled argument. It would be possible to add special rules to allow function ~l:p1 -> e1 | ... | ~l:pn -> en This was actually the case in olabl, but it was very rarely used, and complicates the parser and type checker. Jacques --------------------------------------------------------------------------- Jacques Garrigue Kyoto University garrigue at kurims.kyoto-u.ac.jp <A HREF=http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/>JG</A>