Constants

From dis-Emi-A

Jump to: navigation, search


Constants are obviously a part of every language, though their handling in an auto-typed language needs to be a little more complex.

Here is a piece of code with a constant in it:

plus_five :> x -> y
{
	y = x + 5;
}

This is fairly straight-forward, except, if we consider 5 to be only an integer then this function works only for integers. If we consider it to be float, then not for integers. There are two ways to solve this problem, Auto upcasting/promotion or allowing 5 to be multiple types.

Given the reasons against promotion we'll stick with giving 5 multiple types. That is, the above function produces these scenarios:

  1. 5 as an Integer
  2. 5 as a Float
  3. 5 as a Complex


However, given a constant 5.0 then only the Float and Complex versions will be considered since the form is now floating point. Furthermore there should be an additional complex form (vector form, matrix form, etc.) which will be properly considered in all its supertypes.

Personal tools