Re:The Ergonomics of Type Checking (2016)
by bastawhiz on Saturday October 28, 2017 @02:58PM
(#15576278)
Many languages do this (type inference), to some extent. The moment you have any expression that can evaluate to more than one type, though, it requires annotations.
[ Parent
| on HN ]
Re:The Ergonomics of Type Checking (2016)
by bitwalker on Saturday October 28, 2017 @03:22PM
(#15576385)
That's not always true, rank-1 polymorphic functions (i.e. functions polymorphic in their argument) don't usually require type annotations. Higher-rank polymorphic functions though do generally require them, because without the annotations type inference is undecidable in the general case for such functions. For example:
pair x y = (x, y)
This function creates a pair for any two types, and doesn't require any annotations.
Re:The Ergonomics of Type Checking (2016)
by hliyan on Saturday October 28, 2017 @03:03PM
(#15576308)
Are there any languages that do it beyond the first value assignment, or outside the current scope? Also, any languages that subsequently revise the type definition?
Re:The Ergonomics of Type Checking (2016)
by tedmiston on Saturday October 28, 2017 @06:35PM
(#15577030)
Not sure if this is exactly what you're asking but one can reassign variables to change their types in Python:
>>> x = 1
>>> type(x)
<class 'int'>
>>> x = 'foo'
>>> type(x)
<class 'str'>I believe the question was about inferred static typing for union types. Python does not do any static type inference.
Also, I'm not sure how a union type could be distinguished from an error during type inference. Maybe a nullable, but otherwise it'd be very tricky.