Alex Rivera | Logout

What is a Type?

Asked 2009-08-05T13:34:32.660
12

A newb question /+: ...
In programming, we come across the word Type frequently enough.

What should it be meant to convey, and when should it not be used?

Edit
Report

3 Answers

6

Data is nothing but a collection of bits. A type tells you what those bits represent like int, char, Boolean.

answered 2009-08-05T13:46:13.597
4

Here's the best definition I have ever come across:

A proof is a program. The hypothesis that it proves is a type for the program.

Here, "program" is meant very generally, and refers to any construct in your programming language that can be reasoned about in that language (be it an irreducible value, an expression, a function, or an entire application).

Some programming languages, so-called "statically typed" languages, include an ancillary language (called a type system) for making statements about programs. Statements that, if the program is correct, should always be true. So, in a sense, types are also programs, interpreted by a further program called a type-checker. Some type systems require the programmer to make explicit statements about types, where the type-checker ensures that your programs correspond with those statements and will give you an error if they don't. Other systems try to infer the most general type for your programs (i.e. the most general hypothesis that the program proves) automatically and will give you an error if no such type can be inferred.

answered 2009-08-05T15:19:27.737
1

In terms of data types, it's the format in which the data is stored in memory and conveys the operations that can be performed on and with the data.

For example, an 'unsigned integer' is a data type that can only store positive whole real numbers (i.e 0, 1, 2, 3...), usually up to a specific number due to the fact that the memory allocated to the unsigned integer is limited.

answered 2009-08-05T13:42:46.550

Your Answer