Is there a semantic difference between type "annotation" and "ascription"?

In the following example, I usually describe u32 as a "type annotation".

let x: u32 = 5;

However, I have seen others on this forum refer to it as a "type ascription".

The compiler seems to use the term "annotation":

error[E0282]: type annotations needed
 --> src/main.rs:2:9
  |
2 |     let x = "hello".chars().collect();
  |         ^ consider giving `x` a type

But there is also an unimplemented RFC for type ascription, which would allow users to specify types in more places.

Why is there a difference in terminology here? To me, both the compiler error and the RFC refer to two applications of the exact same concept, yet they use different words for it.

Linguistically, "ascription" seems a bit more forceful than "annotation". An annotation usually provides some extra information, whereas an ascription insists upon a fundamental attribute. If I had to choose one, I suppose "ascription" would be a better fit, but "annotation" is far more common in everyday speech, so it's a tough choice.

Is there some subtle difference I'm not seeing? If so, does it justify using a different term?

I would consider it like the difference between

let x = &y;

and

let ref x = y;

where one is an expression and the other is part of the pattern binding. (Well, not actually part of a pattern right now technically, but I'd like it to be eventually.)

Basically, an annotation goes on a declaration, and an ascription goes on an expression or value.

5 Likes

That's not really my question though. I guess I have two points:

  1. It doesn't seem very useful to apply different names to the same concept in slightly different contexts (declarations vs. expressions).

  2. In practice, I've seen people refer to what you call a type annotation as a type ascription, and vice versa.

If they are used nearly synonymously and represent the exact same concept, then what utility is there in having different names? It seems like it would be better to just pick one.

Or maybe this is all just colloquial usage, and the compiler will always refer to them as annotations?

1 Like

Beige and tan are slightly different colors. They have different names because in some contexts, there are people who care about those slight differences. You can call them both brown in another context, but just because you don't care about a distinction doesn't mean there's no motivation for it. You just don't share that motivation. The compiler devs do care about the difference between type annotation and type ascription because it matters during compiler development.

For instance, one of the important differences to consider is that of precedence. With type annotations there's not a lot of concern about precedence because most types are declared with some kind of bracketing construct. However, expressions are much more flexible, so the precedence of a type ascription operator matters quite a bit.

5 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.