# Is constant a variable or subtype?

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?

• 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. – jmite May 30 '13 at 17:22
• 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? – Val May 31 '13 at 16:37
• 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. – jmite May 31 '13 at 16:41
• 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? – Val May 31 '13 at 17:16
• 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. – babou Jun 4 '13 at 23:26

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.