]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.databoard/src-isv/spec/Type System.mediawiki
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / src-isv / spec / Type System.mediawiki
index 5742c498094d5f992e04e34f0338ce0ad77b7fba..83e9f9058a456e26877227578661805a732d40eb 100644 (file)
-=Type-system=\r
-DataBoard is a software library built upon a simple but well formulated and expressive type system. The design is a compromise of expression power, advanced functions, and performance. In total there are 13 types; 7 primitive types, and 6 structural.\r
-\r
-; Primitive Types\r
-{| border="1" cellpadding="3" cellspacing="0" align="center" \r
-|'''#'''\r
-|'''Datatype'''\r
-|'''Description'''\r
-|- style="background-color: #f9f9f9;"\r
-|0||Boolean||true and false\r
-|- style="background-color: #ffffff;"\r
-|1||Byte||signed 8-bit integers\r
-|- style="background-color: #f9f9f9;"\r
-|2||Integer||signed 32-bit integers\r
-|- style="background-color: #ffffff;"\r
-|3||Long||signed 64-bit integers\r
-|- style="background-color: #f9f9f9;"\r
-|4||Float||32-bit IEEE 754 floating point numbers\r
-|- style="background-color: #ffffff;"\r
-|5||Double||64-bit IEEE 754 floating point numbers\r
-|- style="background-color: #f9f9f9;"\r
-|6||String||Unicode strings of arbitrary length\r
-|}\r
-\r
-; Structural types\r
-{| border="1" cellpadding="3" cellspacing="0" align="center" \r
-|'''#'''||'''Datatype'''||'''Description'''\r
-|- style="background-color: #f9f9f9;"\r
-|7||Record||Contains constant set of fields\r
-|- style="background-color: #ffffff;"\r
-|8||Array||An ordered collection of values\r
-|- style="background-color: #f9f9f9;"\r
-|9||Map||An object that maps keys to values\r
-|- style="background-color: #ffffff;"\r
-|10||Optional||A container that either has or does not have a value\r
-|- style="background-color: #f9f9f9;"\r
-|11||Union||A choise between component types.\r
-|- style="background-color: #ffffff;"\r
-|12||Variant||An object that can contain a value of any type\r
-|}\r
-\r
-==Meta-Data==\r
-Annotations add meta data to a base type. They determine the set of valid values.\r
-\r
-Different primitive types and datatype constructions support different annotations:\r
-{| border="1" cellpadding="3" cellspacing="0" align="center"\r
-|'''types/constructor'''\r
-|'''annotations supported'''\r
-|- style="background-color: #f9f9f9;"\r
-|Byte, Integer, Long, Float, Double \r
-|range, unit\r
-|-\r
-|String\r
-|pattern, mimeType, length\r
-|- style="background-color: #f9f9f9;"\r
-|Array\r
-|length\r
-|-\r
-|Record\r
-|referable\r
-|}\r
-    \r
-==Record==\r
-A record type is a sequence of components. Each component has a type and a name. The name is a unrestricted Unicode string.\r
-The set of (well-formed/valid) values of the record type is a cartesian product of the (well-formed/valid) values of the component types. Recursion in Datatypes is based on referable records.\r
-\r
-==Union==\r
-A union type is defined with a sequence of components similarly as a record type. \r
-The set of (well-formed/valid) values of the union type is disjoint union of the (well-formed/valid) values of the component types.\r
-\r
-==Array==\r
-An array type is constructed with a base type. Its values are finite sequences of the base type.\r
-\r
-==Map==\r
-A map type is constructed with a base type of key and value. Its values are finite sequence of entries of key-value pairs. Keys may not refer even indirectly to the map itself.\r
-\r
-==Variants==\r
-Variant consists of type and a value. \r
-    \r
-==Sub-typing==\r
-Datatypes do not support explicit subtyping (most of its uses can be replaced by using Union-constructor), \r
-but it can be defined implicitly: a datatype\r
-A is a ''subtype'' of B, if all valid values of A are also valid values of B. Primitive\r
-datatypes and type constructors are defined so that if A is a subtype of B then\r
-they have the same set of well-formed values.\r
-\r
-==Validation==\r
-''Datatype'' is a mathematical object that is associated with two sets: ''well-formed'' \r
-and ''valid'' values, where the former set contains the latter. A datatype\r
-is ''basic'' if its well-formed values are all valid. ''Primitive datatypes'' are basic data\r
-types that are completely defined by their set of valid values. There is only a\r
-finite set of primitive datatypes. ''Structured datatypes'' are constructed from other\r
-types. \r
-\r
-The distinction between well-formed and valid values can be demonstrated\r
-with the following example: <code>"http://www.simantics.org/"</code> is a valid value of\r
-datatype URI. <code>"foo::bar"</code> is not a valid URI, but it is well-formed i.e. it can\r
-be represented in all contexts where URIs are used. The number 34 is not a\r
-well-formed URI. Similarly, if Probability is defined as a floating point number between 0 and 1, \r
-then 1.5 is well-formed but not a valid value of <code>Probability</code>.\r
-\r
-==Comparison==\r
-Two data values can be compared and put into order. There is a rule for each type. Structural values are compared in in-order. \r
-{| border="1" cellpadding="3" cellspacing="0" align="center"\r
-|'''Type'''\r
-|'''Compare-function'''\r
-|- style="background-color: #f9f9f9;"\r
-|RecordType\r
-|Field by field in order*\r
-|-\r
-|UnionType\r
-|by tag, if equals then by value. '''DataTypes''' have the following order: ArrayType, BooleanType, ByteType, IntegerType, LongType, FloatType, DoubleType, OptionalType, RecordType, StringType, UnionType, VariantType, MapType\r
-|- style="background-color: #f9f9f9;"\r
-|NumberType\r
-|compare values\r
-|-\r
-|ArrayType\r
-|compare lengths, then elements \r
-|- style="background-color: #f9f9f9;"\r
-|OptionalType\r
-|Compare ''HasValue'', then ''Value''\r
-|-\r
-|StringType\r
-|Case-sensitive String compare\r
-|- style="background-color: #f9f9f9;"\r
-|BooleanType\r
-|zero if values are the same; a positive value if the first value represents true and the second false; a negative value if the first is false and send true\r
-|-\r
-|VariantType\r
-|compare type, then value\r
-|- style="background-color: #f9f9f9;"\r
-|MapType\r
-|1. Compare Sizes, 2. Eliminate method : pair comparison of highest entries. Take highest key entries of both maps. Compare key, compare value. If equal go to the next entry, else use the compare value of (key then value).\r
-|}\r
-\r
-==Default Value==\r
-There is a default value specified for all datatypes.\r
-\r
-{| border="1" cellpadding="3" cellspacing="0" align="center"\r
-|'''Type'''\r
-|'''Default Value'''\r
-|- style="background-color: #f9f9f9;"\r
-|RecordType\r
-|Each field according to type.\r
-|-\r
-|UnionType\r
-|Tag 0 with default value of the composite type.\r
-|- style="background-color: #f9f9f9;"\r
-|Byte, Integer, Long, Float, Double\r
-|0 or min limit if range exists.\r
-|-\r
-|MapType\r
-|no entries\r
-|- style="background-color: #f9f9f9;"\r
-|Array\r
-|Minimum number of entries where each entry has the default value of the composite type.\r
-|-\r
-|OptionalType\r
-|No value.\r
-|- style="background-color: #f9f9f9;"\r
-|String\r
-|"" or minimum value if pattern exists\r
-|- \r
-|Boolean\r
-|false\r
-|- style="background-color: #f9f9f9;"\r
-|Variant\r
-|{} : void\r
-|}\r
-\r
-==Hash Function==\r
-There is a hash function specified for each type of value. The result is a 32-bit integer. \r
-\r
-{| border="1" cellpadding="3" cellspacing="0" align="center"\r
-|'''Type'''\r
-|'''Hash-function'''\r
-|- style="background-color: #f9f9f9;"\r
-|Boolean\r
-|true=1231, false=1237\r
-|-\r
-|Integer\r
-|value\r
-|- style="background-color: #f9f9f9;"\r
-|''Long''\r
-|lower 32-bits ^ higher 32-bits\r
-|-\r
-|Float\r
-|''IEEE 754 floating-point "single format" bit layout'' as is.\r
-|- style="background-color: #f9f9f9;"\r
-|''Double''\r
-|lower 32-bits ^ higher 32-bits of ''IEEE 754 floating-point "double format" bit layout.''\r
-|-\r
-|Optional\r
-|no value = 0, else <tt>hash(value)</tt>\r
-|- style="background-color: #f9f9f9;"\r
-|Array\r
-|<tt>int result = 1; for (int element : array) result = 31 * result + hash(element);</tt>\r
-|-\r
-|Record\r
-|<tt>int result = 3; for (field : record) result = 31 * result + hash(field)*;</tt>\r
-|- style="background-color: #f9f9f9;"\r
-|Variant\r
-|<tt>hash(type) + hash(value)</tt>\r
-|-\r
-|Union\r
-|<tt>tag + hash(value)</tt>\r
-|- style="background-color: #f9f9f9;"\r
-|Map\r
-|<tt>int result = 0; for (entry : map) result += hash(key) ^ hash(value);</tt>\r
-|-\r
-|Byte\r
-|value\r
-|}\r
-\r
- *) In case of recursion, where the hash-function enters an referable data value a second/consecutive time, \r
-    0 is considered as the hash value.\r
-\r
-\r
-\r
+=Type-system=
+DataBoard is a software library built upon a simple but well formulated and expressive type system. The design is a compromise of expression power, advanced functions, and performance. In total there are 13 types; 7 primitive types, and 6 structural.
+
+; Primitive Types
+{| border="1" cellpadding="3" cellspacing="0" align="center" 
+|'''#'''
+|'''Datatype'''
+|'''Description'''
+|- style="background-color: #f9f9f9;"
+|0||Boolean||true and false
+|- style="background-color: #ffffff;"
+|1||Byte||signed 8-bit integers
+|- style="background-color: #f9f9f9;"
+|2||Integer||signed 32-bit integers
+|- style="background-color: #ffffff;"
+|3||Long||signed 64-bit integers
+|- style="background-color: #f9f9f9;"
+|4||Float||32-bit IEEE 754 floating point numbers
+|- style="background-color: #ffffff;"
+|5||Double||64-bit IEEE 754 floating point numbers
+|- style="background-color: #f9f9f9;"
+|6||String||Unicode strings of arbitrary length
+|}
+
+; Structural types
+{| border="1" cellpadding="3" cellspacing="0" align="center" 
+|'''#'''||'''Datatype'''||'''Description'''
+|- style="background-color: #f9f9f9;"
+|7||Record||Contains constant set of fields
+|- style="background-color: #ffffff;"
+|8||Array||An ordered collection of values
+|- style="background-color: #f9f9f9;"
+|9||Map||An object that maps keys to values
+|- style="background-color: #ffffff;"
+|10||Optional||A container that either has or does not have a value
+|- style="background-color: #f9f9f9;"
+|11||Union||A choise between component types.
+|- style="background-color: #ffffff;"
+|12||Variant||An object that can contain a value of any type
+|}
+
+==Meta-Data==
+Annotations add meta data to a base type. They determine the set of valid values.
+
+Different primitive types and datatype constructions support different annotations:
+{| border="1" cellpadding="3" cellspacing="0" align="center"
+|'''types/constructor'''
+|'''annotations supported'''
+|- style="background-color: #f9f9f9;"
+|Byte, Integer, Long, Float, Double 
+|range, unit
+|-
+|String
+|pattern, mimeType, length
+|- style="background-color: #f9f9f9;"
+|Array
+|length
+|-
+|Record
+|referable
+|}
+    
+==Record==
+A record type is a sequence of components. Each component has a type and a name. The name is a unrestricted Unicode string.
+The set of (well-formed/valid) values of the record type is a cartesian product of the (well-formed/valid) values of the component types. Recursion in Datatypes is based on referable records.
+
+==Union==
+A union type is defined with a sequence of components similarly as a record type. 
+The set of (well-formed/valid) values of the union type is disjoint union of the (well-formed/valid) values of the component types.
+
+==Array==
+An array type is constructed with a base type. Its values are finite sequences of the base type.
+
+==Map==
+A map type is constructed with a base type of key and value. Its values are finite sequence of entries of key-value pairs. Keys may not refer even indirectly to the map itself.
+
+==Variants==
+Variant consists of type and a value. 
+    
+==Sub-typing==
+Datatypes do not support explicit subtyping (most of its uses can be replaced by using Union-constructor), 
+but it can be defined implicitly: a datatype
+A is a ''subtype'' of B, if all valid values of A are also valid values of B. Primitive
+datatypes and type constructors are defined so that if A is a subtype of B then
+they have the same set of well-formed values.
+
+==Validation==
+''Datatype'' is a mathematical object that is associated with two sets: ''well-formed'' 
+and ''valid'' values, where the former set contains the latter. A datatype
+is ''basic'' if its well-formed values are all valid. ''Primitive datatypes'' are basic data
+types that are completely defined by their set of valid values. There is only a
+finite set of primitive datatypes. ''Structured datatypes'' are constructed from other
+types. 
+
+The distinction between well-formed and valid values can be demonstrated
+with the following example: <code>"http://www.simantics.org/"</code> is a valid value of
+datatype URI. <code>"foo::bar"</code> is not a valid URI, but it is well-formed i.e. it can
+be represented in all contexts where URIs are used. The number 34 is not a
+well-formed URI. Similarly, if Probability is defined as a floating point number between 0 and 1, 
+then 1.5 is well-formed but not a valid value of <code>Probability</code>.
+
+==Comparison==
+Two data values can be compared and put into order. There is a rule for each type. Structural values are compared in in-order. 
+{| border="1" cellpadding="3" cellspacing="0" align="center"
+|'''Type'''
+|'''Compare-function'''
+|- style="background-color: #f9f9f9;"
+|RecordType
+|Field by field in order*
+|-
+|UnionType
+|by tag, if equals then by value. '''DataTypes''' have the following order: ArrayType, BooleanType, ByteType, IntegerType, LongType, FloatType, DoubleType, OptionalType, RecordType, StringType, UnionType, VariantType, MapType
+|- style="background-color: #f9f9f9;"
+|NumberType
+|compare values
+|-
+|ArrayType
+|compare lengths, then elements 
+|- style="background-color: #f9f9f9;"
+|OptionalType
+|Compare ''HasValue'', then ''Value''
+|-
+|StringType
+|Case-sensitive String compare
+|- style="background-color: #f9f9f9;"
+|BooleanType
+|zero if values are the same; a positive value if the first value represents true and the second false; a negative value if the first is false and send true
+|-
+|VariantType
+|compare type, then value
+|- style="background-color: #f9f9f9;"
+|MapType
+|1. Compare Sizes, 2. Eliminate method : pair comparison of highest entries. Take highest key entries of both maps. Compare key, compare value. If equal go to the next entry, else use the compare value of (key then value).
+|}
+
+==Default Value==
+There is a default value specified for all datatypes.
+
+{| border="1" cellpadding="3" cellspacing="0" align="center"
+|'''Type'''
+|'''Default Value'''
+|- style="background-color: #f9f9f9;"
+|RecordType
+|Each field according to type.
+|-
+|UnionType
+|Tag 0 with default value of the composite type.
+|- style="background-color: #f9f9f9;"
+|Byte, Integer, Long, Float, Double
+|0 or min limit if range exists.
+|-
+|MapType
+|no entries
+|- style="background-color: #f9f9f9;"
+|Array
+|Minimum number of entries where each entry has the default value of the composite type.
+|-
+|OptionalType
+|No value.
+|- style="background-color: #f9f9f9;"
+|String
+|"" or minimum value if pattern exists
+|- 
+|Boolean
+|false
+|- style="background-color: #f9f9f9;"
+|Variant
+|{} : void
+|}
+
+==Hash Function==
+There is a hash function specified for each type of value. The result is a 32-bit integer. 
+
+{| border="1" cellpadding="3" cellspacing="0" align="center"
+|'''Type'''
+|'''Hash-function'''
+|- style="background-color: #f9f9f9;"
+|Boolean
+|true=1231, false=1237
+|-
+|Integer
+|value
+|- style="background-color: #f9f9f9;"
+|''Long''
+|lower 32-bits ^ higher 32-bits
+|-
+|Float
+|''IEEE 754 floating-point "single format" bit layout'' as is.
+|- style="background-color: #f9f9f9;"
+|''Double''
+|lower 32-bits ^ higher 32-bits of ''IEEE 754 floating-point "double format" bit layout.''
+|-
+|Optional
+|no value = 0, else <tt>hash(value)</tt>
+|- style="background-color: #f9f9f9;"
+|Array
+|<tt>int result = 1; for (int element : array) result = 31 * result + hash(element);</tt>
+|-
+|Record
+|<tt>int result = 3; for (field : record) result = 31 * result + hash(field)*;</tt>
+|- style="background-color: #f9f9f9;"
+|Variant
+|<tt>hash(type) + hash(value)</tt>
+|-
+|Union
+|<tt>tag + hash(value)</tt>
+|- style="background-color: #f9f9f9;"
+|Map
+|<tt>int result = 0; for (entry : map) result += hash(key) ^ hash(value);</tt>
+|-
+|Byte
+|value
+|}
+
+ *) In case of recursion, where the hash-function enters an referable data value a second/consecutive time, 
+    0 is considered as the hash value.
+
+
+
     
\ No newline at end of file