0
$\begingroup$

I think of type as a range of values that the variable can take whereas the rest is known constant or does not matter. Variables (instances or objects), which share common properties, are considered to belong to the same type/kind/class. That is, the type properties are constant across the type. The type is actually a common property of a class of objects (variables). The variables have a variable part, which may change, making them flipping from one subtype to the other. However, the same applies to subtypes: subtypes also share a common constant property.

I may describe a class by a circle in Vienn Diagramm. Its subspheres would be types or variables. I think that the variable means that it has some fixed part, its type, and variable part, which make it variable and not constant. The constants or values would be an elementary point in the diagramm.

For instance, integer is a subtype of real. Integer variable means that it can take concrete values within the range of the integer area. Similarly, boolean variables, taking only values 0 and 1, are subtype of integer. But, what is a constant 1? Is it a real or integer or boolean variable or it is a specific type, instances of which have a common property: they have a value of 1? Is it a known treatment?

My interest stems from the practice: how can I save memory fixing the common part of variables in a language processing framework?

$\endgroup$
  • $\begingroup$ Not sure how widespread this view is, but my Languages professor said that thinking of types as sets of values was the totally wrong approach. Rather, types are defined by the operations you can perform on them. $\endgroup$ – jmite May 30 '13 at 17:22
  • $\begingroup$ I see no problem to apply operations to values. I usually perform operations on values. Does your professor performs operations on types? How does this look like? $\endgroup$ – Val May 31 '13 at 16:37
  • $\begingroup$ No, certainly values are what you perform operations on. But it's that the correct way to think about a single type is not as a specific set of values, but as a set of things which we can perform a certain set of operations on. $\endgroup$ – jmite May 31 '13 at 16:41
  • $\begingroup$ As I say, a class describes a set of values. You can perform a set of operations on them. If operation cannot be applied to a value, the value has inappropriate properties (belongs to a different type). Where is the problem? $\endgroup$ – Val May 31 '13 at 17:16
  • $\begingroup$ Indeed, obviously, types are useful only with associated operations. But the precise definition of what is a type varies from language to language. I dodged the issue by talking only of sets, without mentionning the operations. Except for pure functional languages, types are not really sets of values as their elements may contain assignable place holders. Then types are often implementation techniques to represent values that can even be mathematically infinite entities. This duality implementation-abstraction calls for other concepts, such as class or signature, also language dependent. $\endgroup$ – babou Jun 4 '13 at 23:26
2
$\begingroup$

This seems very confused. Probably you should state which programming language you are referring to as some of these concepts may have different definitions depending on the language or formalism. Much is arbitrary (possibly not always too consistent). For example, you do not necessarily have booleans as a subtype of integers.

One important issue is to distinguish syntax (what you write to talk about entities) from semantics (the actual entities you wish to talk about). In a simple world, a type may be understood as a set of values that the language can manipulate through specific representations. A constant is a representation of a specific value. In many languages, a constant is a name that is given to a specific value in a given context. A variable is a place holder for a value, that may change. Now this is to be interpreted a bit differently depending on the type of programming langusge, notably imperative of functional (there are other kinds).

Things get more complicated when you start aggregating values in various ways, because some language will let you consider aggregates where some components may change.

You should probably go back to a textbook on programming languages.

P.S. I agree that considering types as sets of values is too simplistic. But I am trying here to make as simple an answer as I can. This is precisely why considering boolean as a subtype of integer may not always be a good idea, or may not be as simple as it may seem.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.