# Typing by value

I wondered if there was a generalized name for typing a variable by assigning a specific value to it. For instance

  a = 4


This would make the variable a an integer, since 4 is an integer. Likewise

  b = 0.8


is b a float in this instance.

Technically this is not dynamic typing (since there is only one defined type, it is just written as the value), but then how is this form called?

• en.wikipedia.org/wiki/Type_inference – JimN Dec 14 '17 at 23:17
• Note that things may not always be a clear-cut as you think. Why int and not long, short, or double here? Implementations and answers differ between languages. – Raphael Dec 15 '17 at 11:10

Determining the type of a variable from the type of the value that is assigned to it is a form of type inference.

In dynamically typed languages, variables usually don't have types, only values have types. In statically typed languages, variables do have types. Most modern statically typed general purpose languages have a form of type inference that can at least infer the type of a variable from the type of what is assigned to it.

Type inference can infer types in other circumstances. The power of type inference depends on the language: full type inference limits the expressive power of the language, as there are many useful typed languages where full type inference is undecidable, but type verification is easy. Different languages make different compromises on automatic inference vs expressiveness.

• So if I understood correctly, type inference is used, but not limited to dynamic languages, right? – Murad Babayev Dec 15 '17 at 8:05
• @MuradBabayev Type inference is a feature of some statically typed languages. In most dynamically typed languages, it isn't even meaningful since the language doesn't have a concept of relating a type to a variable. – Gilles 'SO- stop being evil' Dec 15 '17 at 10:51
• @MuradBabayev Type inference, if powerful enough, makes statically types code look similar to code in "dynamic" languages. That doesn't mean "dynamic" languages use type inference. They don't, as Gilles explains. – Raphael Dec 15 '17 at 11:12
• That makes sense. Approving. – Murad Babayev Dec 15 '17 at 21:20
• @Gilles But then, what is the term "implicit typing", and how does it differ? – Murad Babayev Dec 16 '17 at 9:38