A data type is a semantic classification of a set of values. In other words it is a set of values which share extra information, whether it is intensional, extensional or otherwise. Some examples of types are: integers, floating point numbers, complex numbers, characters, arrays, strings, shapes, null-type, etc.
The primary role of a data type is to describe actions behaviour that make sense on sets of values. For instance multiplication can be abstractly defined for integer values whereas it would nonsensical to multiply boolean or string values. Type is used by some people to refer to structure, but in Heron this is too narrow of a view.
Heron is a statically typed language, this means that the type of every expression and value is known at compile-time. Static typing makes it easier for a compiler to optimize code, and check for errors at compile-time. Static typing has the trade-off in that certain kinds of algorithms and software designs require more code to describe when dynamic typing is not available. Heron allows limited dynamic typing through the use of interface references, but this is a one-way relationship. Heron interfaces can be cast from classes, but not back to the originator class.
Heron is type-safe. Type safety means that a type can not be, either explicitly or inadvertently, cast to or used as another incompatible type. This virtually eliminates a source of a class of particularly nasty errors which occur frequently in C++, and are can occur, albeit with less frequency, in Java ( http://matrix.research.att.com/vj/bug.html )
To be precise an implementation of Heron is type-safe only if the implementation of external modules are well-behaved. External modules in Heron, just as with any language which supports external linkage, may corrupt type safety.
The different kinds of types in Heron are: literal primitive types, classes, interfaces ( not implemented in Heron2C yet ), enums ( not implemented in Heron2C yet ), code-blocks, meta-primitives, and references. Any type can be aliased using the define keyword.
There are four ways a programmer can define new types in Heron: a class, an interface, a type-alias ( define ), or an enumeration ( enum ).
A type alias is a new name for an existing type using the define keyword. A type alias is very similar to a typedef in C++, but with one very important difference. A Heron type-alias can be parameterized. This makes Heron metaprogramming syntax far more readable and manageable.
There are two type aliases that are defined for every class: self which refers to the current class type, and inherited which refers to the inherited type of the current class scope. Self is always public, while inherited is always private.
This functionality is not yet supported in Heron2C
Classes may contain nested types which are either public or private in visibility. A public nested type may be referred to by prefixing it with classname::.
An uninstantiable type, is one which can not be instantiated, i.e. constructed, dynamically on the heap or statically on the stack. Meta-primitives and code-blocks are examples of uninstantiable types.
A code block is a sequence of statements enclosed in curly braces. A code-block can be used as an uninstantiable type. That is to say you can declare a type-alias for a code block, and you can pass a code-block as a type parameter to a template. There is a separate page dedicated to code blocks.
Heron allows all constant literal values, to be treated as uninstantiable types. These are called meta-primitives. They are crucial for performing compile-time computations, i.e. doing metaprogramming.
Classes and interface type can be parameterized. A parameterized type is sometimes called a template or a generic. A parameterized type, is a type that is defined in terms of one or more other types that are passed at parameters whenever the type is used (e.g. to declare a variable). The most common example of a parameterized type, and one that exists in a large number of programming languages whether or not they explicitly support user defined templates, is an array. An array is a type, that is defined as a sequence of vales of another type. To use the example of Pascal / Delphi we would could declare an array of integers as follows:
types
IntArray : array of integer;
In Heron the syntax is different but the idea is the same:
types {
define IntArray : Array<Int>
}
In Heron though, a programmer can implement whichever parameterized types they want.