X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fsrc-isv%2Fspec%2FType%20System.mediawiki;h=83e9f9058a456e26877227578661805a732d40eb;hb=09428742cceaabef182dbaacb05368513e21a591;hp=5742c498094d5f992e04e34f0338ce0ad77b7fba;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git
diff --git a/bundles/org.simantics.databoard/src-isv/spec/Type System.mediawiki b/bundles/org.simantics.databoard/src-isv/spec/Type System.mediawiki
index 5742c4980..83e9f9058 100644
--- a/bundles/org.simantics.databoard/src-isv/spec/Type System.mediawiki
+++ b/bundles/org.simantics.databoard/src-isv/spec/Type System.mediawiki
@@ -1,220 +1,220 @@
-=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: "http://www.simantics.org/"
is a valid value of
-datatype URI. "foo::bar"
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 Probability
.
-
-==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 hash(value)
-|- style="background-color: #f9f9f9;"
-|Array
-|int result = 1; for (int element : array) result = 31 * result + hash(element);
-|-
-|Record
-|int result = 3; for (field : record) result = 31 * result + hash(field)*;
-|- style="background-color: #f9f9f9;"
-|Variant
-|hash(type) + hash(value)
-|-
-|Union
-|tag + hash(value)
-|- style="background-color: #f9f9f9;"
-|Map
-|int result = 0; for (entry : map) result += hash(key) ^ hash(value);
-|-
-|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.
-
-
-
+=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: "http://www.simantics.org/"
is a valid value of
+datatype URI. "foo::bar"
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 Probability
.
+
+==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 hash(value)
+|- style="background-color: #f9f9f9;"
+|Array
+|int result = 1; for (int element : array) result = 31 * result + hash(element);
+|-
+|Record
+|int result = 3; for (field : record) result = 31 * result + hash(field)*;
+|- style="background-color: #f9f9f9;"
+|Variant
+|hash(type) + hash(value)
+|-
+|Union
+|tag + hash(value)
+|- style="background-color: #f9f9f9;"
+|Map
+|int result = 0; for (entry : map) result += hash(key) ^ hash(value);
+|-
+|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