Category:Types

From Mesham
Revision as of 21:49, 10 January 2010 by Polas (talk | contribs)
Jump to navigationJump to search

Overview

A type can follow a number of different syntactic forms. The abstract syntax of a type is detailed in the table below. Where elementtype is defined in the type library, varname represents a variable name and type :: type represents type combination to coerce into a new supertype.

type =   elementtype
	| compoundtype
	| type :: type 
	| varname

Compound types are also listed in the type library, to give the reader a flavour they may contain a number of different subcategories of type

compoundtype =   attribute
		| allocation
		| collection 
		| primitive communication
		| communication mode
		| partition
		| distribution
		| composition
		| extended types

Declarations

Syntax

var name:type;

Where type, as explained, is an elementtype, a compoundtype, variable name or type :: type. The operator : sets the type and :: is type combination (coercion).

= Semantics

This will declare a variable to be a specific type. Type combination is subject to a number of semantic rules. If no type information is given, then the type will be found via inference where possible.

Examples

var i:Int :: allocated[multiple[]];

Here the variable i is declared to be integer, allocated to all processes. There are three types included in this declaration, the element type Int and the compound types allocated and multiple. The type multiple is provided as an argument to the allocation type allocated, which is then combined with the Int type.

var m:String;

In this example, variable m is declared to be of type String. For programmer convenience, by default, the language will automatically assume to combine this with allocated[multiple] if such allocation type is missing.

= Statements

Syntax

name:type;

Semantics

Will modify the type of an already declared variable via the : operator. Note, allocation information may not be changed.

Examples

var i:Int :: allocated[multiple[]];
i:=23;
i:i :: const[];

Here the variable i is declared to be integer, allocated to all processes and its value is set to 23. Later on in the code the type is modified to set it also to be constant (so from this point on the programmer may not change the variable's value.) In this third line i:i :: const[]; sets the type of i to be that of i combined with the const type.\twolines{}

Important Rule - Changing the type will not have any runtime code generation in itself, although the modified semantics will affect how the variable behaves from that point on.

Expressions

Syntax

name::type

Semantics

When used as an expression, a variable's type can be coerced with additional types just for that expression.

Example

var i:Int :: allocated[multiple[]];
(i :: channel[1,2]):=82;
i:=12;

This code will declare i to be an integer, allocated on all processes. On line 2 i :: channel[1,2] will combine the channel type (primitive communication) just for that assignment and then on line 3 the assignment happens as a normal integer. This is because on line 2 we have not set the type of i, just modified it for that assignment.

Pages in category ‘Types’

The following 3 pages are in this category, out of 3 total.