On 13-07-30 08:53 AM, Andreas Rossberg wrote:
Let a lurker nitpick on a false dichotomy in this comparison. There are three
separate things going on that the current discussion seems to confuse:
1. The syntax of type annotations.
2. The syntax of function types.
3. The syntax of function definitions.
Very fair point.
ML, Caml, Haskell, Coq, Agda, as well as Scala, and practically all higher-order languages with strong roots in type theory
consistently use ":" for (1) and "->" for (2) (sometimes lexical variations like "::" or
"=>").
Moreover, function definitions tend to be viewed as a special kind of
equational pattern match where the pattern happens to be a function
application. So in all these languages, a fully-annotated function definition
would be written with a _colon_, too, contrary to what the above list seems to
suggest. That's because it's just another type annotation of a pattern:
f(x : t1) : t2 = exp
annotates "f(x)" with the type t2. The type of f itself, on the other hand, would
be written f : t1 -> t2. And
g(x : t) : u -> v = exp
is the definition of a function that results in a function, so that g : t -> (u
-> v).
Yeah. I was ... aware that the defining-forms varied orthogonally a bit
but didn't really know how to summarize them across languages; I guess
"a special kind of pattern" is the best summary, though many languages
in the lists I mentioned don't even _have_ pattern grammars. But thanks
for the clarification.
It reminds me somewhat of the asymmetry between (T,U,V) tuple
expressions and their type (T*U*V) in the MLs. An asymmetry I feel ...
is a bit of a wart? We've tried to keep the expression, pattern and type
grammars looking as similar as possible.
This is pretty much the standard notation in type-theoretic literature or
related languages (although some, notably Haskell, place more restrictions on
function definitions and don't allow an inline return type annotation at all).
Note how it's both readable and internally consistent. The Rust syntax arguably
less so, although it's probably not worth changing.
Trickier call. We don't allow type ascription inside patterns, only at
the outermost level. I think we found that our grammars were
sufficiently similar that intermixing them inside one another produced
ambiguities, though I don't remember off hand which one. Possibly the
ambiguity between "{<field_name>:<pat>}" and "{<field_name>:<ty>}".
Again: "everyone wants the colon" :)
-Graydon
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev