logoalt Hacker News

MangoToupeyesterday at 5:37 AM3 repliesview on HN

It doesn't. Either the optional type annotations have precise semantics or they don't.


Replies

dragonwriteryesterday at 8:35 AM

The annotations have fairly well defined semantics, the behavior of typecheckers in the absence of annotations, where types are ambiguous (a common case being when the type is a generic collection type but the defining position is assignment to an empty collection so that the correct specialization of the generic type is ambiguous) is less defined.

dwatttttyesterday at 5:57 AM

What should a type checker say about this code?

  x = []
  x.append(1)
  x[0] = "new"
  x[0] + "oops"

It's optionally typed, but I would credit both "type checks correctly" and "can't assign 'new' over a number" as valid type checker results.
show 3 replies
sagarmyesterday at 5:57 AM

They don't. They're just documentation.