# What is a type definition?

When reading about data types, "type definition" is often used without any prior explanation to what it means.

For example, in https://en.wikipedia.org/wiki/Type_system, we have the sentence "... since C++ has stronger rules regarding type definitions ..."

Any help in clarifying what the difference between, for example, type and type definition is greatly appreciated!

• Do you know what a type is? Then, a type definition is, as the term suggests, the definition of a type. I'm not sure what your real question is here. – Raphael May 5 '17 at 5:15

"Defining" a type is the act of building a new type composed of one or more pre-existing data types. For example, the "Complex Number" type is often declared as an ordered pair of "Real Numbers" :

Type Complex
Real a
Real b
End


a and b being the real and imaginary parts.

This sample of pseudo-code is a "Type Definition".

• I don't think this is what's being asked... Defining an abstract data type is of course a type definition, but has nothing to do with strong or weak typing (part of the question) – EL Dendo May 5 '17 at 10:08

Variables can contain different sorts of values, e.g., integers, reals, characters... This is called the TYPE of the variable. Some languages are dynamically typed. That means that the interpreter or the compiler decides the type of the variable for you. In static typed languages, you have to define the type yourself when declaring the variable. This is the TYPE DEFINITION.

In a strong typed static languages the rules forbid to mix different types. if you want to add, e.g., a real and an integer you have to explicitly cast the integer to real.

in a weak typed language you can mix types. but since the low level bitpatterns differs between types, you can have unwanted results.

Most languages are somewhere in between. It will be clear that unwanted effects are not acceptable, while the need for an explicit cast makes the code heavy. So most compilers will do an implicit cast for some standard operations. Adding a real and an integer will in that case implicitly provoke a cast to real.

• What is "p.e."? Also, I don't see how what you've written after the first paragraph relates to the question. – David Richerby May 5 '17 at 11:11
• @ David: p.e. = exempli gratia = For the sake of example = for instance... The sentence "... since C++ has stronger rules regarding type definitions ..." shows in my opinion that the question is asked in the context of weak and strong typing. – EL Dendo May 5 '17 at 12:11
• Aha -- that's "e.g.", in English -- edited. – David Richerby May 5 '17 at 12:17
• indeed it is. my mistake. – EL Dendo May 5 '17 at 12:19
• This answer demonstrates a variety of serious misunderstandings of types and type systems. Virtually every sentence of this answer is incorrect, confusing, or misleading. As a start, type systems are not just about variables: 3+'a' doesn't involve any variables but will be type checked. Dynamically "typed" language implementations don't "decide" the type of anything. Implicit conversions don't make a language more "dynamically" or "weakly" typed. Generally, static and dynamic "typing" are not opposite ends of a spectrum but are simply talking about different things entirely. – Derek Elkins May 5 '17 at 22:18