News for hackers. Stuff that matters.
Re:The Ergonomics of Type Checking (2016) by pizza234 on Saturday October 28, 2017 @03:03PM (#15576305)
You're describing type inference.

An example is Crystal; [edited] example from the website:

  if rand(2) > 0
    my_string = "hello world"
  end
  puts my_string.upcase

  Execution:

  $ crystal hello_world.cr
  Error in hello_world.cr:4: undefined method 'upcase' for Nil (compile-time type is (String | Nil))
Re:The Ergonomics of Type Checking (2016) by hliyan on Saturday October 28, 2017 @03:08PM (#15576325)
I edited my comment to explain further -- I'm talking about going beyond the initial assignment...
Re:The Ergonomics of Type Checking (2016) by bcherny on Saturday October 28, 2017 @03:57PM (#15576531)
This is a well explored area. Wikipedia article is short but has some good references [0].

Languages like Haskell, OCaml, F#, and Elm use global type inference.

Languages like Scala and TypeScript use local type inference. TypeScript in particular uses flowed type inference (there might be a more formal name for this). For example:

  let a = document.querySelector('#a') // typeof a is Element | null
  
  if (a == null) throw 'not found'     // typeof a is now Element
[0] https://en.wikipedia.org/wiki/Type_inference
Re:The Ergonomics of Type Checking (2016) by nytopop on Saturday October 28, 2017 @03:23PM (#15576395)
Check out the hindley milner type system [1]. It's used by haskell and some other languages, and allows for a very extensive amount of type inference. You can often write large sections of code with no type annotations and the compiler can figure out the most general type based on the type of some function called somewhere, which means the thing you did with that result must be of a certain class of types, which makes the surrounding expressions' types have to be a certain class of types, etc etc.

[1] https://en.wikipedia.org/wiki/Hindley%E2%80%93Milner_type_sy...

Re:The Ergonomics of Type Checking (2016) by cwzwarich on Saturday October 28, 2017 @03:38PM (#15576456)
I think it's fair to say that (GHC) Haskell no longer really uses the Hindley-Milner type system. It doesn't have let generalization (except in a few restricted cases), and it doesn't have principal types, which I would consider to be the two distinguishing features of HM.
Re:The Ergonomics of Type Checking (2016) by danharaj on Saturday October 28, 2017 @05:09PM (#15576768)
Let generalization should only be disabled if one uses the GADT type extension and even then can be turned on in addition to GADTs. While Haskell isn't really Hindley-Milner, it's close enough for most development.