[null,{"project":"newurtype","version":"0.0.0","unit":"struct","info":"....","$unit_flags$":{"kind_of_unit":"value","kind_of_value_unit":"static_value","type_of_value_unit":"struct","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","target_platform":"universal_target","target_dialect":"es5_target_dialect","overall_source_dialect":"all_es6","overall_value_scope":"custom_value_scope","overall_augmentation":"custom_augmentation","overall_value_existence":"all_unit_implemented","static_type_check":"type_check","session_verification":"verify_sessions","document_executability":"no_executable_document","target_minification":"no_minification"},"$name$":"","$value$":"Object.create (null)","$info$":"
....
\n","$markdown_caption$":"global constant extensible ⌂ : STRUCT","$html_caption$":"global constant extensible ⌂ : STRUCT"},["doc_1",{"unit":"doc","header":"**The preliminary `__Type` constructor**","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"doc_1","$header$":"The preliminary__Type
constructor","$markdown_caption$":"1. **The preliminary `__Type` constructor**","$html_caption$":"1. The preliminary __Type
constructor"}],["doc_2",{"unit":"doc","header":"`__Type` for the preliminary type definition","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"doc_2","$header$":"__Type
for the preliminary type definition","$markdown_caption$":"2. `__Type` for the preliminary type definition","$html_caption$":"2. __Type
for the preliminary type definition"}],["__Type",{"unit":"construct","name":"__Type","value":"function (obj) {\n // 1. create `this`; i.e. the type result\n var keyL = Object.keys (obj);\n for (var i = 0; i < keyL.length; i++) {\n var key = keyL[i];\n this[__Type.hideId (key)] = obj[key];\n }\n // 2. make `this` iterable, if possible\n var it = null; // for the optional `ITERATOR`\n if (obj.iterator) {\n it = obj.iterator;\n } else if (obj.members) {\n var xL = obj.members ();\n if (xL !== null) {\n it = (function () {\n var i = 0;\n var next = function () {\n if (i < xL.length) { return { done: false, value: xL[i++] }; }\n else { return { done: true , value: undefined }; }\n };\n return { next: next };\n }) ();\n }\n }\n if (it !== null) {\n this [Symbol.iterator] = function () { return it; }\n }\n}","info":"`__Type` is the constructor and class for our type objects.\n\nThe type instantiation with `new __Type(obj)` is only used for the urtypes.\nA call of `Type.fromRecord(obj)` has the same semantics, only that it is safer to use, because it complains when `obj` does not comprise the mandatory properties.\nFor more information, see the [_Types_ doc unit](#ROOT--Types).\n\nIf `obj` has either an `obj.iterator` object or `obj.members` function defined, the resulting `__Type` value is made iterable.","comment":"Make this `construct` a `local construct` later on.\n\nEssential (and that needs to be checked) is the fact that `Type.construct(OBJECT):TYPE` complies with the main composition function `Type.create(OBJECT):TYPE` defined later on in the `type` tofu.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"construct","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"__Type","$value$":"function (obj) {\n // 1. create `this`; i.e. the type result\n var keyL = Object.keys (obj);\n for (var i = 0; i < keyL.length; i++) {\n var key = keyL[i];\n this[__Type.hideId (key)] = obj[key];\n }\n // 2. make `this` iterable, if possible\n var it = null; // for the optional `ITERATOR`\n if (obj.iterator) {\n it = obj.iterator;\n } else if (obj.members) {\n var xL = obj.members ();\n if (xL !== null) {\n it = (function () {\n var i = 0;\n var next = function () {\n if (i < xL.length) { return { done: false, value: xL[i++] }; }\n else { return { done: true , value: undefined }; }\n };\n return { next: next };\n }) ();\n }\n }\n if (it !== null) {\n this [Symbol.iterator] = function () { return it; }\n }\n}","$info$":"__Type
is the constructor and class for our type objects.
The type instantiation with new __Type(obj)
is only used for the urtypes. A call of Type.fromRecord(obj)
has the same semantics, only that it is safer to use, because it complains when obj
does not comprise the mandatory properties. For more information, see the Types doc unit.
If obj
has either an obj.iterator
object or obj.members
function defined, the resulting __Type
value is made iterable.
Make this construct
a local construct
later on.
Essential (and that needs to be checked) is the fact that Type.construct(OBJECT):TYPE
complies with the main composition function Type.create(OBJECT):TYPE
defined later on in the type
tofu.
...
\n","$markdown_caption$":"global constant extensible __Type.hideId : Type.lambda ([EcmaScript.IDENTIFIER, EcmaScript.IDENTIFIER])","$html_caption$":"global constant extensible __Type.hideId : Type.lambda ([EcmaScript.IDENTIFIER, EcmaScript.IDENTIFIER])"}],["unhideId",{"unit":"function","name":"__Type.unhideId","type":"Type.lambda ([EcmaScript.IDENTIFIER, EcmaScript.IDENTIFIER])","value":"function (i) {\n return i.slice (2, i.length -2);\n}","info":"...","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"__Type.unhideId","$value$":"function (i) {\n return i.slice (2, i.length -2);\n}","$info$":"...
\n","$markdown_caption$":"global constant extensible __Type.unhideId : Type.lambda ([EcmaScript.IDENTIFIER, EcmaScript.IDENTIFIER])","$html_caption$":"global constant extensible __Type.unhideId : Type.lambda ([EcmaScript.IDENTIFIER, EcmaScript.IDENTIFIER])"}],["toString",{"unit":"proto","name":"__Type.toString","type":"Type.fun ([NULL, STRING])","value":"function () {\n if (this.__name__) { return ('[type ' + this.__name__ + ']'); }\n else { return ('[type ...]') }\n}","info":"...","$unit_flags$":{"kind_of_value_unit":"proto","type_of_value_unit":"any","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"__Type.toString","$value$":"function () {\n if (this.__name__) { return ('[type ' + this.__name__ + ']'); }\n else { return ('[type ...]') }\n}","$info$":"...
\n","$markdown_caption$":"global constant extensible __Type::toString : Type.fun ([NULL, STRING])","$html_caption$":"global constant extensible __Type::toString : Type.fun ([NULL, STRING])"}]],["doc_3",{"unit":"doc","header":"**The Urtypes**","info":"# Urtypes\n\n## The native ECMAScript (ES6) types\n\n `undefined`\n `null`\n boolean\n number\n string\n symbol (new in ES6)\n object\n array\n function\n (regular expression)\n\nThe `typeof` operator\n\n Type `typeof x`\n -------------------------------- --------------------\n `undefined` `'undefined'`\n `null` `'object'` (!)\n boolean `'boolean'`\n number `'number'`\n string `'string'`\n symbol (new in ES6) `'symbol'`\n object `'object'`\n array `'object'`\n function `'function'`\n (regular expression) `'object'`\n\n## The Urtype hierarchy\n\nThe __urytpe hierachy__ of all ECMAScript (ES6) values is this\n\n`undefined`\n`null`\nboolean\nnumber\nstring\nsymbol (new in ES6)\nobject\n array\n function\n (regular expression)
\nThe typeof
operator
Type `typeof x`\n-------------------------------- --------------------\n`undefined` `'undefined'`\n`null` `'object'` (!)\nboolean `'boolean'`\nnumber `'number'`\nstring `'string'`\nsymbol (new in ES6) `'symbol'`\nobject `'object'`\n array `'object'`\n function `'function'`\n (regular expression) `'object'`
\nThe urytpe hierachy of all ECMAScript (ES6) values is this
\n ANYTHING\n / \\\n / \\\n / \\\n IMPROPER_VALUE VALUE---------------------------\n / | / \\\n / | / \\\n / | / \\\nUNDEFINED NOT_A_NUMBER PRIMITIVE ----------- OBJECT------\n / | \\ \\ \\ / | \\ \\\n / | \\ \\ \\ | | \\ \\\n / | \\ \\ \\ / | \\ \\\n / | \\ \\ \\ / | \\ \\\n NULL BOOLEAN NUMBER STRING SYMBOL ARRAY RECORD TYPE FUNCTION\n | | |\n | | |\n INT CHAR LIST\n\n . . . . .\n \\ \\ | / /\n NOTHING
\n\n\n\n
\n- \n
\n
ANYTHING
is the type of all (improper or proper) values\n
- \n
\n
IMPROPER_VALUE
for the two improper values\n
- \n
UNDEFINED
- \n
NOT_A_NUMBER
the type of the singleNaN
value- \n
\n
VALUE
for the type of all proper values\n
- \n
\n
PRIMITIVE
is the type of all the proper primitive values\n
- \n
NULL
for the single valuenull
- \n
BOOLEAN
forfalse
andtrue
- \n
\n
NUMBER
is the type of all proper numbers\n
- \n
INT
is the type of all safe/small integers- \n
\n
STRING
for all strings\n
- \n
CHAR
is the type of all characters, i.e. all strings of length1
- \n
SYMBOL
for the symbols (new in ES6)- \n
\n
OBJECT
is the type of all proper objects\n
- \n
\n
ARRAY
is the type of all arrays\n
- \n
LIST
is the type of all lists, i.e. arrays that can be represented by an array literal[x_1, ..., x_n]
of proper values.- \n
RECORD
the type of all records or plain objects, that can be represented by an object literal- \n
TYPE
is the type of all types- \n
FUNCTION
the type of all functions (including constructors and generators)- \n
NOTHING
is the type that has no members.
Note, that
\nNUMBER
value) is any ECMAScript number value, including Infinity
, -Infinity
, -0
etc. but without NaN
(which is indeed "not a number").n
with -(2^53-1) = -9007199254740991 <= n <= 9007199254740991 = 2^53+1
.x
with typeof x
value "object"
, but other than null
.x
with Array.isArray(x) === true
.[x_1,...,x_n]
, where each x
is a (proper or improper) value. In other words, an array a
of length n
is a list if and only if its keys are (the strings values of the integers) 0
, 1
, ..., n-1
.null
) object is said to be a plain object or record, if it can be represented by an object literal {k_1: x_1, ..., k_n: x_n}
.OBJECT
value) is any object o
(i.e. typeof o === 'object'
) other than null
.Every urtype is a proper type, i.e. like any other TYPE
value, every urtype u
has the same functionality defined:
Type.chi (u) (x)
returns true
or false
, depending on whether x
is a member of u
or not.Type.complain (u) (x)
returns a complain string, i.e.
x
is a member of u
, then there is no complain and the result is the empty string ''
x
is not a member of u
, then the complain (string) is not empty, and gives a hint why that is not so.Type.members (u)
.................Type.cardinality (u)
.............
Urtype.of (x)
........
\nUrtype.supremum ([x_1, ..., x_n])
..........................
\n","$header$":"The Urtypes","$markdown_caption$":"3. **The Urtypes**","$html_caption$":"3. The Urtypes"}],["doc_4",{"unit":"doc","header":"The single Urtypes","$unit_flags$":{"kind_of_unit":"doc"},"$name$":"doc_4","$header$":"The single Urtypes","$markdown_caption$":"4. The single Urtypes","$html_caption$":"4. The single Urtypes"}],["ANYTHING",{"unit":"type","name":"ANYTHING","type":"URTYPE","value":"new __Type ({\n complain : function (x) { return ''; },\n chi : function (x) { return true; },\n name : 'ANYTHING',\n cardinality : function () { return null; },\n members : function () { return null; }\n})","info":"`ANYTHING` is the type of all (proper or improper) values.\n\n`ANYTHING` is thus a kind of universal and default type: everything is a member of `ANYTHING`:\n\n* `Type.chi (ANYTHING) (x)` is `true`, for every input `x`.\n* `Type.complain (ANYTHING) (x)` is the empty string `''`, for every input `x`.\n* `Type.cardinality (ANYTHING)` is `null`, because `ANYTHING` is infinitely many members.\n* `Type.members (ANYTHING)` is `null`, too, because we cannot list infinitely many members.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"type","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"ANYTHING","$value$":"new __Type ({\n complain : function (x) { return ''; },\n chi : function (x) { return true; },\n name : 'ANYTHING',\n cardinality : function () { return null; },\n members : function () { return null; }\n})","$info$":"ANYTHING
is the type of all (proper or improper) values.
ANYTHING
is thus a kind of universal and default type: everything is a member of ANYTHING
:
Type.chi (ANYTHING) (x)
is true
, for every input x
.Type.complain (ANYTHING) (x)
is the empty string ''
, for every input x
.Type.cardinality (ANYTHING)
is null
, because ANYTHING
is infinitely many members.Type.members (ANYTHING)
is null
, too, because we cannot list infinitely many members.IMPROPER_VALUE
is the type of the two improper values, namely undefined
and NaN
. Every other value, i.e. every other member of ANTHING
, is a proper value (or member of []VALUE
](#VALUE)).
As there are only two improper values at all, we can list them
\n> Type.members (IMPROPER_VALUE)\n[undefined, NaN]
\nFor example,
\n> Type.chi (IMPROPER_VALUE) (NaN)\ntrue
\n","$markdown_caption$":"global constant extensible IMPROPER_VALUE : URTYPE","$html_caption$":"global constant extensible IMPROPER_VALUE : URTYPE"}],["UNDEFINED",{"unit":"type","name":"UNDEFINED","type":"URTYPE","value":"new __Type ({\n complain : function (x) {\n if (typeof x === 'undefined') { return ''; }\n else { return \"The value is not `undefined`'.\"; }\n },\n chi : function (x) { return (typeof x === 'undefined'); },\n name : 'UNDEFINED',\n cardinality : function () { return 1; },\n members : function () { return [undefined]; }\n})","info":"`UNDEFINED` is the type of the one single improper value `undefined`.\n\n > Type.members (UNDEFINED)\n [ undefined ]\n\nProper values are always \"defined\", i.e. not `undefined`.\nBut `undefined` can be the value of expressions, i.e. the result of an evaluation of that expression.\n\nNote the difference between an __undeclared__ variable/identifier and an __undefined__ variable/identifier.\nIf an identifier is undeclared, its value is not `undefined`, but its evaluation throws an error (`ReferenceError`).\nFor example, if `foo` is not declared, then a REPL session in NodeJs is this\n\n > foo\n Reference Error: foo is not defined\n\nBut if `foo` is declared before (with a `var` statement), calling `foo` is not an error, but returns `undefined`\n\n > var foo\n undefined\n\n > foo\n undefined\n\nAccordingly, the value of an undeclared identifier, say `bar`, is not a member of `UNDEFINED`:\n\n > Type.chi (UNDEFINED) (bar)\n ReferenceError: bar is not defined\n\nbut if the variable is declared\n\n > var bar\n undefined\n\nthen\n\n > Type.chi (UNDEFINED) (bar)\n true","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"type","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"UNDEFINED","$value$":"new __Type ({\n complain : function (x) {\n if (typeof x === 'undefined') { return ''; }\n else { return \"The value is not `undefined`'.\"; }\n },\n chi : function (x) { return (typeof x === 'undefined'); },\n name : 'UNDEFINED',\n cardinality : function () { return 1; },\n members : function () { return [undefined]; }\n})","$info$":"UNDEFINED
is the type of the one single improper value undefined
.
> Type.members (UNDEFINED)\n[ undefined ]
\nProper values are always "defined", i.e. not undefined
. But undefined
can be the value of expressions, i.e. the result of an evaluation of that expression.
Note the difference between an undeclared variable/identifier and an undefined variable/identifier. If an identifier is undeclared, its value is not undefined
, but its evaluation throws an error (ReferenceError
). For example, if foo
is not declared, then a REPL session in NodeJs is this
> foo\nReference Error: foo is not defined
\nBut if foo
is declared before (with a var
statement), calling foo
is not an error, but returns undefined
> var foo\nundefined\n\n> foo\nundefined
\nAccordingly, the value of an undeclared identifier, say bar
, is not a member of UNDEFINED
:
> Type.chi (UNDEFINED) (bar)\nReferenceError: bar is not defined
\nbut if the variable is declared
\n> var bar\nundefined
\nthen
\n> Type.chi (UNDEFINED) (bar)\ntrue
\n","$markdown_caption$":"global constant extensible UNDEFINED : URTYPE","$html_caption$":"global constant extensible UNDEFINED : URTYPE"}],["NOT_A_NUMBER",{"unit":"type","name":"NOT_A_NUMBER","type":"URTYPE","value":"new __Type ({\n complain : function (x) {\n if (isNaN (x)) { return ''; }\n else { return \"The value is not `NaN`.\"; }\n },\n chi : function (x) { return isNaN (x); },\n name : 'NOT_A_NUMBER',\n cardinality : function () { return 1; },\n members : function () { return [NaN]; }\n})","info":"`NOT_A_NUMBER` is the type of the one single improper value `NaN`.\n\n > Type.members (NOT_A_NUMBER)\n [ NaN ]\n\nIn JavaScript/ECMAScript, `NaN` serves as an exceptional result for numeric operations. For example, the division `0/0` or the multiplication `\"hi\" * 5` of a string and a number return `NaN`. Other programming languages would throw an error in these cases, but JavaScript is designed as a forgiving language and has this special (improper) value for these cases.\n\nAs `NaN` is the result of meaningless numeric operations, `NaN` is itself a numeric value in JavaScript/ECMAScript, i.e.\n\n > typeof NaN\n 'number'\n\nwhich is on the other hand very confusing, because `NaN` is an acronym for \"Not-a-Number\".\n\nIn our approach, we properly distinguish between __proper numbers__ and the __improper value__ `NaN`.\n`NUMBER` is the type of all these proper numbers:\n\n > Type.chi (NUMBER) (123.456)\n true\n\n > Type.chi (NUMBER) (NaN)\n false\n\nand for completeness sake, we complement the `NUMBER` type by the single-value type `NOT_A_NUMBER`:\n\n > Type.chi (NOT_A_NUMBER) (NaN)\n true\n\n > Type.chi (NOT_A_NUMBER) (123.456)\n false","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"type","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"NOT_A_NUMBER","$value$":"new __Type ({\n complain : function (x) {\n if (isNaN (x)) { return ''; }\n else { return \"The value is not `NaN`.\"; }\n },\n chi : function (x) { return isNaN (x); },\n name : 'NOT_A_NUMBER',\n cardinality : function () { return 1; },\n members : function () { return [NaN]; }\n})","$info$":"NOT_A_NUMBER
is the type of the one single improper value NaN
.
> Type.members (NOT_A_NUMBER)\n[ NaN ]
\nIn JavaScript/ECMAScript, NaN
serves as an exceptional result for numeric operations. For example, the division 0/0
or the multiplication "hi" * 5
of a string and a number return NaN
. Other programming languages would throw an error in these cases, but JavaScript is designed as a forgiving language and has this special (improper) value for these cases.
As NaN
is the result of meaningless numeric operations, NaN
is itself a numeric value in JavaScript/ECMAScript, i.e.
> typeof NaN\n'number'
\nwhich is on the other hand very confusing, because NaN
is an acronym for "Not-a-Number".
In our approach, we properly distinguish between proper numbers and the improper value NaN
. NUMBER
is the type of all these proper numbers:
> Type.chi (NUMBER) (123.456)\ntrue\n\n> Type.chi (NUMBER) (NaN)\nfalse
\nand for completeness sake, we complement the NUMBER
type by the single-value type NOT_A_NUMBER
:
> Type.chi (NOT_A_NUMBER) (NaN)\ntrue\n\n> Type.chi (NOT_A_NUMBER) (123.456)\nfalse
\n","$markdown_caption$":"global constant extensible NOT_A_NUMBER : URTYPE","$html_caption$":"global constant extensible NOT_A_NUMBER : URTYPE"}],["VALUE",{"unit":"type","name":"VALUE","type":"URTYPE","value":"new __Type ({\n complain:\n function (x) {\n if (typeof x === 'undefined') { return (\"The value is `undefined`, and that is not a proper value.\"); }\n else if (isNaN (x)) { return (\"The value is `NaN`, and that is not a proper value.\"); }\n else { return ''; }\n },\n chi:\n function (x) {\n if (typeof x === 'undefined') { return false; }\n else if (isNaN (x)) { return false; }\n else { return true; }\n },\n name:\n 'VALUE',\n cardinality:\n function () { return Infinity; },\n members:\n function () { return null; }\n})","info":"...","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"type","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"VALUE","$value$":"new __Type ({\n complain:\n function (x) {\n if (typeof x === 'undefined') { return (\"The value is `undefined`, and that is not a proper value.\"); }\n else if (isNaN (x)) { return (\"The value is `NaN`, and that is not a proper value.\"); }\n else { return ''; }\n },\n chi:\n function (x) {\n if (typeof x === 'undefined') { return false; }\n else if (isNaN (x)) { return false; }\n else { return true; }\n },\n name:\n 'VALUE',\n cardinality:\n function () { return Infinity; },\n members:\n function () { return null; }\n})","$info$":"...
\n","$markdown_caption$":"global constant extensible VALUE : URTYPE","$html_caption$":"global constant extensible VALUE : URTYPE"}],["PRIMITIVE",{"unit":"type","name":"PRIMITIVE","type":"URTYPE","value":"new __Type ({\n complain:\n function (x) {\n switch (typeof x) {\n case 'undefined': return (\"`undefined` is a proper primitive, but an improper value.\");\n case 'boolean' : return '';\n case 'number' : return '';\n case 'string' : return ''\n case 'symbol' : return '';\n case 'function' : return (\"A function is not a (proper) primitive value.\");\n case 'object' : if (x === null) { return true; }\n else { return false; };\n default : throw Error (\"Undefined `typeof x` result: `\" + typeof x + \"`.\");\n }\n },\n chi:\n function (x) {\n switch (typeof x) {\n case 'undefined': return false;\n case 'boolean' : return true;\n case 'number' : return true;\n case 'string' : return true;\n case 'symbol' : return true;\n case 'function' : return false;\n case 'object' : if (x === null) { return true; }\n else { return false; };\n default : throw Error (\"Undefined `typeof x` result: `\" + typeof x + \"`.\");\n }\n },\n name:\n 'PRIMITIVE',\n cardinality:\n function (x) { return Infinity; },\n members:\n function (x) { return null; }\n})","info":"...","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"type","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"PRIMITIVE","$value$":"new __Type ({\n complain:\n function (x) {\n switch (typeof x) {\n case 'undefined': return (\"`undefined` is a proper primitive, but an improper value.\");\n case 'boolean' : return '';\n case 'number' : return '';\n case 'string' : return ''\n case 'symbol' : return '';\n case 'function' : return (\"A function is not a (proper) primitive value.\");\n case 'object' : if (x === null) { return true; }\n else { return false; };\n default : throw Error (\"Undefined `typeof x` result: `\" + typeof x + \"`.\");\n }\n },\n chi:\n function (x) {\n switch (typeof x) {\n case 'undefined': return false;\n case 'boolean' : return true;\n case 'number' : return true;\n case 'string' : return true;\n case 'symbol' : return true;\n case 'function' : return false;\n case 'object' : if (x === null) { return true; }\n else { return false; };\n default : throw Error (\"Undefined `typeof x` result: `\" + typeof x + \"`.\");\n }\n },\n name:\n 'PRIMITIVE',\n cardinality:\n function (x) { return Infinity; },\n members:\n function (x) { return null; }\n})","$info$":"...
\n","$markdown_caption$":"global constant extensible PRIMITIVE : URTYPE","$html_caption$":"global constant extensible PRIMITIVE : URTYPE"}],["NULL",{"unit":"type","name":"NULL","type":"URTYPE","value":"new __Type ({\n complain : function (x) {\n if (x === null) { return ''; }\n else { return \"The value is not `null`.\"; }\n },\n chi : function (x) { return (x === null); },\n name : 'NULL',\n cardinality : function () { return 1; },\n members : function () { return [null]; }\n})","info":"............","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"type","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"NULL","$value$":"new __Type ({\n complain : function (x) {\n if (x === null) { return ''; }\n else { return \"The value is not `null`.\"; }\n },\n chi : function (x) { return (x === null); },\n name : 'NULL',\n cardinality : function () { return 1; },\n members : function () { return [null]; }\n})","$info$":"............
\n","$markdown_caption$":"global constant extensible NULL : URTYPE","$html_caption$":"global constant extensible NULL : URTYPE"}],["BOOLEAN",{"unit":"type","name":"BOOLEAN","type":"URTYPE","value":"new __Type ({\n complain : function (x) {\n if (typeof x === 'boolean') { return ''; }\n else { return \"The value is not a boolean.\"; }\n },\n chi : function (x) { return (typeof x === 'boolean'); },\n name : 'BOOLEAN',\n cardinality : function () { return 2; },\n members : function () { return [false, true]; }\n})","info":"......","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"type","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"BOOLEAN","$value$":"new __Type ({\n complain : function (x) {\n if (typeof x === 'boolean') { return ''; }\n else { return \"The value is not a boolean.\"; }\n },\n chi : function (x) { return (typeof x === 'boolean'); },\n name : 'BOOLEAN',\n cardinality : function () { return 2; },\n members : function () { return [false, true]; }\n})","$info$":"......
\n","$markdown_caption$":"global constant extensible BOOLEAN : URTYPE","$html_caption$":"global constant extensible BOOLEAN : URTYPE"}],["NUMBER",{"unit":"type","name":"NUMBER","type":"URTYPE","value":"new __Type ({\n complain : function (x) {\n if (typeof x === 'number') {\n if (isNaN (x)) { return \"`NaN` is not a proper number.\"; }\n else { return ''; }\n } else {\n return \"The value is not a (proper) number.\";\n }\n },\n chi : function (x) { return (typeof x === 'number'); },\n name : 'NUMBER',\n cardinality : function () { return null; },\n members : function () { return null; }\n})","info":"`NUMBER` is the type of all __proper numbers__, i.e. all native ECMAScript number values, except `NaN`.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"type","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"NUMBER","$value$":"new __Type ({\n complain : function (x) {\n if (typeof x === 'number') {\n if (isNaN (x)) { return \"`NaN` is not a proper number.\"; }\n else { return ''; }\n } else {\n return \"The value is not a (proper) number.\";\n }\n },\n chi : function (x) { return (typeof x === 'number'); },\n name : 'NUMBER',\n cardinality : function () { return null; },\n members : function () { return null; }\n})","$info$":"NUMBER
is the type of all proper numbers, i.e. all native ECMAScript number values, except NaN
.
INT
is the type of small/safe integers, i.e. all numbers n
so that
n
is not NaN
(i.e. n
is a proper number)n
is an integer, i.e. has no fraction part.n
is inside the range -(2^53-1) = -9007199254740991 <= n <= 9007199254740991 = 2^53+1
.For example,
\n> Type.complain (INT) ('hallo')\n'`INT` complain: The value is not a number'\n\n> Type.complain (INT) (123.456)\n'`INT` complain: The number is not an integer, it has a fraction part `0.45600000000000307`.'\n\n> Type.complain (INT) (12345678901234567890)\n'`INT` complain: The number is bigger than the greatest defined integer.'\n\n> Type.complain (INT) (-12345678901234567890)\n'`INT` complain: The number is smaller than the least defined integer.'\n\n> Type.complain (INT) (-123)\n''\n\n> Type.cardinality (INT)\nnull\n\n> Type.members (INT)\nnull\n\n> Type.expression (INT)\n'INT'
\nNote, that there is also Number.isSafeInteger(x)
in ES6, with the same semantics as INT.chi(x)
.
Define an iterator
property!!!
STRING
is the type of all the string values.
Make STRING
iterable, i.e. define an iterator
property!!!
CHAR
is the type of all the characters, i.e. strings of length 1
.
Make CHAR
iterable, i.e. define an iterator
property!!!
SYMBOL
is the type of all symbols (introduced in ES6), i.e. all values x
with typeof x
returning 'symbol'
.
A list is an array that is fully represented by an array literal [x_1,...,x_n]
, where each x
is a (proper or improper) value.
In other words, an array a
of length n
is a list if and only if its keys are (the strings values of the integers) 0",
1, ...,
n-1`.
Note, that [123, undefined, 234, NaN, 345]
is a list, but [123, , , 234, , , 345]
is not.
For example,
\n> LIST.complain ([123,243])\n''\n\n> LIST.complain ([123,,,243])\n'The array has length `4`, but only `2` indices are defined.'\n\n> LIST.complain (123)\n'The value is not a list, because it is not an array.'\n\n> var a = [123,234]; a.foo = 345; a\n[ 123, 234, foo: 345 ]\n\n> LIST.complain (a)\n'The given array only has length `2`, but there are `3` keys.'
\n","$markdown_caption$":"global constant extensible LIST : URTYPE","$html_caption$":"global constant extensible LIST : URTYPE"}],["RECORD",{"unit":"type","name":"RECORD","type":"URTYPE","value":"new __Type ({\n complain:\n function (x) {\n if (typeof x === 'object' && x !== null) {\n var p = Object.getPrototypeOf (x);\n if (p === null) { return ''; } // `x` is a proper record\n else if (p === Object.prototype) { return ''; } // `x` is an improper record\n else { return 'The given object is not a record.'; }\n } else {\n return (\"The value is not a proper object and thus not a record.\");\n }\n },\n chi:\n function (x) {\n return ( typeof x === 'object'\n && x !== null\n && ( Object.getPrototypeOf (x) === null\n || Object.getPrototypeOf (x) === Object.prototype ) );\n },\n name:\n 'RECORD',\n cardinality:\n function () { return Infinity; },\n members:\n function () { return null; }\n})","info":"A (proper, i.e. non-`null`) object is said to be\n\n* a __plain object__ or __record__, if it can be represented by an object literal `{k_1: x_1, ..., k_n: x_n}`.\n* a __proper record__, if is a plain object with prototype `null`.\n\nAccordingly, a plain object that is not a proper record, is an __improper record__.\n\n`RECORD` is the type of all (proper or improper) records.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"type","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"RECORD","$value$":"new __Type ({\n complain:\n function (x) {\n if (typeof x === 'object' && x !== null) {\n var p = Object.getPrototypeOf (x);\n if (p === null) { return ''; } // `x` is a proper record\n else if (p === Object.prototype) { return ''; } // `x` is an improper record\n else { return 'The given object is not a record.'; }\n } else {\n return (\"The value is not a proper object and thus not a record.\");\n }\n },\n chi:\n function (x) {\n return ( typeof x === 'object'\n && x !== null\n && ( Object.getPrototypeOf (x) === null\n || Object.getPrototypeOf (x) === Object.prototype ) );\n },\n name:\n 'RECORD',\n cardinality:\n function () { return Infinity; },\n members:\n function () { return null; }\n})","$info$":"A (proper, i.e. non-null
) object is said to be
{k_1: x_1, ..., k_n: x_n}
.null
.Accordingly, a plain object that is not a proper record, is an improper record.
\nRECORD
is the type of all (proper or improper) records.
TYPE
is the type of all types. Internally, a TYPE
value is an instance of the __Type
constructor, but __Type
is local (hidden) and cannot be called directly. The basic TYPE
generator is the function Type.fromRecord(rec)
and rec
has the properties complain
and/or chi
, and name
and/or expression
.
FUNCTION
is the type of all functions, i.e. all values f
with typeof f === 'function'
.
OBJECT
is the type of all proper objects. For example,
> Type.complain (OBJECT) (null)\n'`OBJECT` complain:\\n`null` is not a proper object.'\n\n> Type.complain (OBJECT) (false)\n'`OBJECT` complain:\\nThe `boolean` value is not a proper object.'\n\n> Type.complain (OBJECT) ("hello")\n'`OBJECT` complain:\\nThe `string` value is not a proper object.'\n\n> Type.complain (OBJECT) ({one: 123, two: 234})\n''\n\n> Type.complain (OBJECT) (['a', 'b', 'c'])\n''\n\n> Type.complain (OBJECT) (function (x) { return 123 + x; })\n''\n\n> Type.complain (OBJECT) (Rec.create ({one: 123, two: 234}))\n''\n\n> Type.complain (OBJECT) (OBJECT)\n''
\nWhat native ECMAScript tools could we use to determine, if a value x
is a proper object?
If typeof x
is 'object'
and x
is not null
, then x
is indeed a proper object. But note, that functions are also proper objects, and then typeof x
is 'function'
.
On the other hand if x instanceof Object
, then x
is a proper object. If we use the instanceof
operator, we don't need to take extra care of null
, because null instanceof Object
is false
. But if x
is a proper record, i.e. a plain object with prototype null
, x
is a proper object in our definition, but x instanceof Object
is false
.
ARRAY
is the type of all arrays, i.e. all values a
with Array.isArray(a) === 'true'
.
NOTHING
is the type that has no members, at all.
...
\n","$markdown_caption$":"global constant extensible Urtype : STRUCT","$html_caption$":"global constant extensible Urtype : STRUCT"},["of",{"unit":"function","name":"Urtype.of","type":"Type.lambda ([ANYTHING, Type.finite (Urtype.list)])","value":"function (x) {\n switch (typeof x) {\n case 'undefined': return UNDEFINED;\n case 'boolean' : return BOOLEAN;\n case 'number' : if (isNaN (x)) { return NOT_A_NUMBER; }\n else if (Number.isSafeInteger(x)) { return INT; }\n else { return NUMBER; }\n case 'string' : if (x.length === 1) { return CHAR; }\n else { return STRING; }\n case 'symbol' : return SYMBOL;\n case 'function' : return FUNCTION;\n case 'object' : if (null === x) { return NULL; }\n else if (Type.chi (LIST) (x)) { return LIST; }\n else if (Type.chi (ARRAY) (x)) { return ARRAY; }\n else if (Type.chi (TYPE) (x)) { return TYPE; }\n else if (Type.chi (RECORD) (x)) { return RECORD; }\n else { return OBJECT; }\n default : throw Error (\"Undefined `typeof x` value `\" + (typeof x) + \"`.\");\n }\n}","info":"`Urtype.of(x)` returns the (name of the) __urtype__ of the given value `x`, namely\n\n * `UNDEFINED`, if `x` is a variable that has no proper value assigned, i.e. if `typeof x` is `'undefined'`\n * `BOOLEAN`, if `x` is a boolean value, i.e. if `typeof x` is `'boolean'`\n * `NOT_A_NUMBER`, if `x` is the `NaN` value\n * `INT`, if `x` is a [(safe) integer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger), i.e. an integer strictly in between `-(2^53)` and `2^53`.\n * `NUMBER`, if `typeof x` is `'number'`, but `x` is neither `NaN` nor a safe integer.\n * `CHAR`, if `x` is a string of length `1`\n * `STRING`, if `x` is a string, i.e. if `typeof x` is `'string'`, but with a length other than `1`.\n * `SYMBOL`, if `x` is a symbol (introduced in ES6), i.e. if `typeof x` is `'symbol'`\n * `FUNCTION`, if `x` is a function, i.e. `typeof x` is `'function'`.\n * `NULL`, if `x` is `null`\n * `LIST`, if `x` is a [list](#LIST)\n * `ARRAY`, if `x` is an array (i.e. `Array.isArray(x)` is `true`), but not a list\n * `RECORD`, if `x` is a [record](#RECORD)\n * `TYPE`, if `x` is a [type](#TYPE) in the TofJs sense\n * `OBJECT`, if `x` is an object (i.e. `typeof x` is `'object'`), but `x` is neither an array/list, nor a record, nor a function or a type.\n\nThe urtype of a value `x` compared to the result of a `typeof x` call:\n\n +--------------------+---------------+\n | Urtype.of(x) | typeof x |\n +====================+===============+\n | `UNDEFINED` | `'undefined'` |\n +--------------------+---------------+\n | `BOOLEAN` | `'boolean'` |\n +--------------------+---------------+\n | `NUMBER` | |\n | `NOT_A_NUMBER` | `'number'` |\n | `INT` | |\n +--------------------+---------------+\n | `STRING` | `'string'` |\n | `CHAR` | |\n +--------------------+---------------+\n | 'SYMBOL' | `'symbol'` |\n +--------------------+---------------+\n | 'FUNCTION' | `'function'` |\n +--------------------+---------------+\n | 'NULL' | |\n | 'OBJECT' | |\n | 'ARRAY' | `'object'` |\n | 'LIST' | |\n | 'RECORD' | |\n | 'TYPE' | |\n +--------------------+---------------+\n","comment":"The bullet list in the `info` part is written like a code block. If it is written like a Markdown bullet list, the compiler throws an error message:\n\n FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory\n Aborted\n\nMaybe a bug in the Markdown converter???","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Urtype.of","$value$":"function (x) {\n switch (typeof x) {\n case 'undefined': return UNDEFINED;\n case 'boolean' : return BOOLEAN;\n case 'number' : if (isNaN (x)) { return NOT_A_NUMBER; }\n else if (Number.isSafeInteger(x)) { return INT; }\n else { return NUMBER; }\n case 'string' : if (x.length === 1) { return CHAR; }\n else { return STRING; }\n case 'symbol' : return SYMBOL;\n case 'function' : return FUNCTION;\n case 'object' : if (null === x) { return NULL; }\n else if (Type.chi (LIST) (x)) { return LIST; }\n else if (Type.chi (ARRAY) (x)) { return ARRAY; }\n else if (Type.chi (TYPE) (x)) { return TYPE; }\n else if (Type.chi (RECORD) (x)) { return RECORD; }\n else { return OBJECT; }\n default : throw Error (\"Undefined `typeof x` value `\" + (typeof x) + \"`.\");\n }\n}","$info$":"Urtype.of(x)
returns the (name of the) urtype of the given value x
, namely
* `UNDEFINED`, if `x` is a variable that has no proper value assigned, i.e. if `typeof x` is `'undefined'`\n* `BOOLEAN`, if `x` is a boolean value, i.e. if `typeof x` is `'boolean'`\n* `NOT_A_NUMBER`, if `x` is the `NaN` value\n* `INT`, if `x` is a [(safe) integer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger), i.e. an integer strictly in between `-(2^53)` and `2^53`.\n* `NUMBER`, if `typeof x` is `'number'`, but `x` is neither `NaN` nor a safe integer.\n* `CHAR`, if `x` is a string of length `1`\n* `STRING`, if `x` is a string, i.e. if `typeof x` is `'string'`, but with a length other than `1`.\n* `SYMBOL`, if `x` is a symbol (introduced in ES6), i.e. if `typeof x` is `'symbol'`\n* `FUNCTION`, if `x` is a function, i.e. `typeof x` is `'function'`.\n* `NULL`, if `x` is `null`\n* `LIST`, if `x` is a [list](#LIST)\n* `ARRAY`, if `x` is an array (i.e. `Array.isArray(x)` is `true`), but not a list\n* `RECORD`, if `x` is a [record](#RECORD)\n* `TYPE`, if `x` is a [type](#TYPE) in the TofJs sense\n* `OBJECT`, if `x` is an object (i.e. `typeof x` is `'object'`), but `x` is neither an array/list, nor a record, nor a function or a type.
\nThe urtype of a value x
compared to the result of a typeof x
call:
+--------------------+---------------+\n| Urtype.of(x) | typeof x |\n+====================+===============+\n| `UNDEFINED` | `'undefined'` |\n+--------------------+---------------+\n| `BOOLEAN` | `'boolean'` |\n+--------------------+---------------+\n| `NUMBER` | |\n| `NOT_A_NUMBER` | `'number'` |\n| `INT` | |\n+--------------------+---------------+\n| `STRING` | `'string'` |\n| `CHAR` | |\n+--------------------+---------------+\n| 'SYMBOL' | `'symbol'` |\n+--------------------+---------------+\n| 'FUNCTION' | `'function'` |\n+--------------------+---------------+\n| 'NULL' | |\n| 'OBJECT' | |\n| 'ARRAY' | `'object'` |\n| 'LIST' | |\n| 'RECORD' | |\n| 'TYPE' | |\n+--------------------+---------------+
\n","$comment$":"The bullet list in the info
part is written like a code block. If it is written like a Markdown bullet list, the compiler throws an error message:
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory\nAborted
\nMaybe a bug in the Markdown converter???
\n","$markdown_caption$":"global constant extensible Urtype.of : Type.lambda ([ANYTHING, Type.finite (Urtype.list)])","$html_caption$":"global constant extensible Urtype.of : Type.lambda ([ANYTHING, Type.finite (Urtype.list)])"}],["list",{"unit":"value","name":"Urtype.list","type":"Type.list (TYPE)","value":"[ ANYTHING,\n IMPROPER_VALUE,\n UNDEFINED,\n NOT_A_NUMBER,\n VALUE,\n PRIMITIVE,\n NULL,\n BOOLEAN,\n NUMBER,\n INT,\n STRING,\n CHAR,\n SYMBOL,\n OBJECT,\n ARRAY,\n LIST,\n RECORD,\n TYPE,\n FUNCTION,\n NOTHING ]","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"any","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Urtype.list","$value$":"[ ANYTHING,\n IMPROPER_VALUE,\n UNDEFINED,\n NOT_A_NUMBER,\n VALUE,\n PRIMITIVE,\n NULL,\n BOOLEAN,\n NUMBER,\n INT,\n STRING,\n CHAR,\n SYMBOL,\n OBJECT,\n ARRAY,\n LIST,\n RECORD,\n TYPE,\n FUNCTION,\n NOTHING ]","$markdown_caption$":"global constant extensible Urtype.list : Type.list (TYPE)","$html_caption$":"global constant extensible Urtype.list : Type.list (TYPE)"}],["names",{"unit":"value","name":"Urtype.names","type":"Type.list (STRING)","value":"list . map (function (t) { return t.name; })","info":"`Urtype.names` is the list of all the names of the urtypes, i.e. `['ANYTHING', 'IMPROPER_VALUE', 'UNDEFINED', ..., 'NOTHING']`.","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"any","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Urtype.names","$value$":"list . map (function (t) { return t.name; })","$info$":"Urtype.names
is the list of all the names of the urtypes, i.e. ['ANYTHING', 'IMPROPER_VALUE', 'UNDEFINED', ..., 'NOTHING']
.
Urtype.namePath(t)
returns the path ['ANYTHING', ..., name]
in the urtype hierarchy (Urtype.tree
) that leads to the name
of the given urtype t
.
For example,
\n> Urtype.namePath (CHAR)\n[ 'ANYTHING', 'VALUE', 'PRIMITIVE', 'STRING', 'CHAR']
\n","$markdown_caption$":"global constant extensible Urtype.namePath : Type.fun ([URTYPE, Type.list (Type.finite (EcmaScript.ID))])","$html_caption$":"global constant extensible Urtype.namePath : Type.fun ([URTYPE, Type.list (Type.finite (EcmaScript.ID))])"}],["path",{"unit":"function","name":"Urtype.path","type":"Type.fun ([ANYTHING, Type.list (EcmaScript.ID)])","value":"function (x) {\n return namePath (of (x));\n}","info":"`Urtype.path (x)` returns the path in the `Urtype.tree` hierarchy, that leads to the (name of the) urtype of `x`.\nWhen the result is `[t_1, ..., t_n]`, it means that `x` is a member of `t_n`, which is a subtype of `t_(n-1)`, which is a subtype of `t_(n-2)`, ..., which is a subtype of `t_1` (whereas `t_1` is always `'ANYTHING'`).\n\nFor example,\n\n > Urtype.path (123.456)\n [ 'ANYTHING', 'VALUE', 'PRIMITIVE', 'NUMBER' ]\n\n > Urtype.path ('hi')\n [ 'ANYTHING', 'VALUE', 'PRIMITIVE', 'STRING' ]\n\n > Urtype.path (STRING)\n [ 'ANYTHING', 'VALUE', 'OBJECT', 'TYPE' ]\n\n > Urtype.path (false)\n [ 'ANYTHING', 'VALUE', 'PRIMITIVE', 'BOOLEAN' ]\n\n > Urtype.path (null)\n [ 'ANYTHING', 'VALUE', 'PRIMITIVE', 'NULL' ]\n\n > Urtype.path ([1,2,3])\n [ 'ANYTHING', 'VALUE', 'OBJECT', 'ARRAY', 'LIST' ]\n\n > Urtype.path ({one: 123})\n [ 'ANYTHING', 'VALUE', 'OBJECT', 'RECORD' ]\n\n > Urtype.path (new Date())\n [ 'ANYTHING', 'VALUE', 'OBJECT' ]\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Urtype.path","$value$":"function (x) {\n return namePath (of (x));\n}","$info$":"Urtype.path (x)
returns the path in the Urtype.tree
hierarchy, that leads to the (name of the) urtype of x
. When the result is [t_1, ..., t_n]
, it means that x
is a member of t_n
, which is a subtype of t_(n-1)
, which is a subtype of t_(n-2)
, ..., which is a subtype of t_1
(whereas t_1
is always 'ANYTHING'
).
For example,
\n> Urtype.path (123.456)\n[ 'ANYTHING', 'VALUE', 'PRIMITIVE', 'NUMBER' ]\n\n> Urtype.path ('hi')\n[ 'ANYTHING', 'VALUE', 'PRIMITIVE', 'STRING' ]\n\n> Urtype.path (STRING)\n[ 'ANYTHING', 'VALUE', 'OBJECT', 'TYPE' ]\n\n> Urtype.path (false)\n[ 'ANYTHING', 'VALUE', 'PRIMITIVE', 'BOOLEAN' ]\n\n> Urtype.path (null)\n[ 'ANYTHING', 'VALUE', 'PRIMITIVE', 'NULL' ]\n\n> Urtype.path ([1,2,3])\n[ 'ANYTHING', 'VALUE', 'OBJECT', 'ARRAY', 'LIST' ]\n\n> Urtype.path ({one: 123})\n[ 'ANYTHING', 'VALUE', 'OBJECT', 'RECORD' ]\n\n> Urtype.path (new Date())\n[ 'ANYTHING', 'VALUE', 'OBJECT' ]
\n","$markdown_caption$":"global constant extensible Urtype.path : Type.fun ([ANYTHING, Type.list (EcmaScript.ID)])","$html_caption$":"global constant extensible Urtype.path : Type.fun ([ANYTHING, Type.list (EcmaScript.ID)])"}],["isSubtypeOf",{"unit":"function","name":"Urtype.isSubtypeOf","type":"Type.lambda ([URTYPE, URTYPE, BOOLEAN])","value":"function (t1) {\n return function (t2) {\n if (t1 === NOTHING) {\n return true; // `NOTHING` is a subtype of every urtype\n } else if (t2 === NOTHING) {\n return false; // no urtype is a subtype of `NOTHING`\n } else {\n var p1 = namePath (t1);\n var p2 = namePath (t2);\n if (p1.length < p2.length) {\n return false;\n } else { // i.e. p1.length >= p2.length\n for (var i = 0; i < p2.length; i++) {\n if (p1[i] !== p2[i]) {\n return false;\n }\n }\n return true;\n }\n }\n }\n}","info":"`Urtype.isSubtypeOf(t1)(t2)` returns `true` if the urtype `t1` is a subtype of the urtype `t2`.\n\nIn general (i.e. not only for urtypes, but for types in general), `t1` is __a subtype of__ `t2`, if each member of `t1` is also a member of `t2`.\n\nFor example,\n\n > Urtype.isSubtypeOf (STRING) (VALUE)\n true // because every string is a proper value\n\n > Urtype.isSubtypeOf (CHAR) (OBJECT)\n false // because a character is a string, which is not a proper object, but a proper primitive value\n\n > Urtype.isSubtypeOf (NOTHING) (FUNCTION)\n true // because `NOTHING` is a subtype of every urtype\n\n > Urtype.isSubtypeOf (BOOLEAN) (NOTHING)\n false // because only `NOTHING` itself is a subtype of `NOTHING`\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Urtype.isSubtypeOf","$value$":"function (t1) {\n return function (t2) {\n if (t1 === NOTHING) {\n return true; // `NOTHING` is a subtype of every urtype\n } else if (t2 === NOTHING) {\n return false; // no urtype is a subtype of `NOTHING`\n } else {\n var p1 = namePath (t1);\n var p2 = namePath (t2);\n if (p1.length < p2.length) {\n return false;\n } else { // i.e. p1.length >= p2.length\n for (var i = 0; i < p2.length; i++) {\n if (p1[i] !== p2[i]) {\n return false;\n }\n }\n return true;\n }\n }\n }\n}","$info$":"Urtype.isSubtypeOf(t1)(t2)
returns true
if the urtype t1
is a subtype of the urtype t2
.
In general (i.e. not only for urtypes, but for types in general), t1
is a subtype of t2
, if each member of t1
is also a member of t2
.
For example,
\n> Urtype.isSubtypeOf (STRING) (VALUE)\ntrue // because every string is a proper value\n\n> Urtype.isSubtypeOf (CHAR) (OBJECT)\nfalse // because a character is a string, which is not a proper object, but a proper primitive value\n\n> Urtype.isSubtypeOf (NOTHING) (FUNCTION)\ntrue // because `NOTHING` is a subtype of every urtype\n\n> Urtype.isSubtypeOf (BOOLEAN) (NOTHING)\nfalse // because only `NOTHING` itself is a subtype of `NOTHING`
\n","$markdown_caption$":"global constant extensible Urtype.isSubtypeOf : Type.lambda ([URTYPE, URTYPE, BOOLEAN])","$html_caption$":"global constant extensible Urtype.isSubtypeOf : Type.lambda ([URTYPE, URTYPE, BOOLEAN])"}],["supremum",{"unit":"function","name":"Urtype.supremum","type":"Type.fun ([Type.list (ANYTHING), URTYPE])","value":"function (xL) {\n\n // sup (path, path) : path\n function sup (p1, p2) {\n var n = Math.min (p1.length, p2.length);\n var p = [];\n for (var i = 0; i < n; i++) {\n if (p1 [i] === p2 [i]) { p.push (p1 [i]); }\n else { return p; }\n }\n return p;\n }\n\n // the main program\n if (xL.length > 0) {\n var p1 = path (xL [0]);\n for (var i = 1; i < xL.length; i++) {\n var p2 = path (xL [i]);\n p1 = sup (p1, p2);\n }\n var t = p1 [p1.length-1];\n var t = eval (t);\n return t;\n } else {\n return NOTHING;\n }\n\n}","info":"`Urtype.supremum ([x_1,...,x_n])` returns the least of all urtypes in the urtype hierarchy `Urtype.tree` that includes all values `x_1`, ..., `x_n` of the given list.\n\nFor example,\n\n > Urtype.supremum ([123, 'Hello!'])\n { complain: [Function],\n chi: [Function],\n name: 'PRIMITIVE',\n cardinality: [Function],\n members: [Function] }\n\nThe result is easier to identify when we only ask for the `name` of the given urtype and thus call\n\n > Urtype.supremum ([123, 'Hello!']) . name\n 'PRIMITIVE'\n\nOther examples then are:\n\n > Urtype.supremum ([123, 123.456]) . name\n 'NUMBER'\n\n > Urtype.supremum ([123, 123.456, Infinity]) . name\n 'NUMBER'\n\n > Urtype.supremum ([123, 123.456, NaN]) . name\n 'ANYTHING'\n\n > Urtype.supremum ([null, false, 'hi', 77]) . name\n 'PRIMITIVE'\n\n > Urtype.supremum ([null, false, 'hi', 77, [1,2,3]]) . name\n 'VALUE'\n\n > Urtype.supremum ([null, false, 'hi', 77, [1,2,3], {one: 123}]) . name\n 'VALUE'\n\nNote that the urtype `NOTHING` is the returned if and only if the given value list is is empty:\n\n > Urtype.supremum ([]) . name\n 'NOTHING'\n\nAnd if the value list only has one value, then `Urtype.supremum ([x])` is the same as `Urtype.of (x)`. For example,\n\n > Urtype.supremum ([123]) . name\n 'INT'\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Urtype.supremum","$value$":"function (xL) {\n\n // sup (path, path) : path\n function sup (p1, p2) {\n var n = Math.min (p1.length, p2.length);\n var p = [];\n for (var i = 0; i < n; i++) {\n if (p1 [i] === p2 [i]) { p.push (p1 [i]); }\n else { return p; }\n }\n return p;\n }\n\n // the main program\n if (xL.length > 0) {\n var p1 = path (xL [0]);\n for (var i = 1; i < xL.length; i++) {\n var p2 = path (xL [i]);\n p1 = sup (p1, p2);\n }\n var t = p1 [p1.length-1];\n var t = eval (t);\n return t;\n } else {\n return NOTHING;\n }\n\n}","$info$":"Urtype.supremum ([x_1,...,x_n])
returns the least of all urtypes in the urtype hierarchy Urtype.tree
that includes all values x_1
, ..., x_n
of the given list.
For example,
\n> Urtype.supremum ([123, 'Hello!'])\n{ complain: [Function],\n chi: [Function],\n name: 'PRIMITIVE',\n cardinality: [Function],\n members: [Function] }
\nThe result is easier to identify when we only ask for the name
of the given urtype and thus call
> Urtype.supremum ([123, 'Hello!']) . name\n'PRIMITIVE'
\nOther examples then are:
\n> Urtype.supremum ([123, 123.456]) . name\n'NUMBER'\n\n> Urtype.supremum ([123, 123.456, Infinity]) . name\n'NUMBER'\n\n> Urtype.supremum ([123, 123.456, NaN]) . name\n'ANYTHING'\n\n> Urtype.supremum ([null, false, 'hi', 77]) . name\n'PRIMITIVE'\n\n> Urtype.supremum ([null, false, 'hi', 77, [1,2,3]]) . name\n'VALUE'\n\n> Urtype.supremum ([null, false, 'hi', 77, [1,2,3], {one: 123}]) . name\n'VALUE'
\nNote that the urtype NOTHING
is the returned if and only if the given value list is is empty:
> Urtype.supremum ([]) . name\n'NOTHING'
\nAnd if the value list only has one value, then Urtype.supremum ([x])
is the same as Urtype.of (x)
. For example,
> Urtype.supremum ([123]) . name\n'INT'
\n","$markdown_caption$":"global constant extensible Urtype.supremum : Type.fun ([Type.list (ANYTHING), URTYPE])","$html_caption$":"global constant extensible Urtype.supremum : Type.fun ([Type.list (ANYTHING), URTYPE])"}],["rank",{"unit":"function","name":"Urtype.rank","type":"Type.lambda ([ANYTHING, INT])","value":"function (x) {\n var u = Urtype.of (x);\n switch (u) {\n case UNDEFINED : return -2;\n case NOT_A_NUMBER : return -1;\n case NULL : return 0;\n case BOOLEAN : return 1;\n case NUMBER : return 2;\n case INT : return 2;\n case STRING : return 3;\n case CHAR : return 3;\n case SYMBOL : return 4;\n case FUNCTION : return 5;\n case TYPE : return 6;\n case LIST : return 7;\n case RECORD : return 8;\n case ARRAY : return 9;\n case OBJECT : return 9;\n default : throw Error (\"Undefined urtype `\" + u + \"`.\");\n }\n}","info":"`Urtype.rank(x)` returns the so-called an integer `i` (`-2 <= i <= 9`), depending on the urtype of `x`, according to the following overview\n\n urtype of `x` rank\n --------------------------- -----\n ANYTHING\n IMPROPER_VALUE\n UNDEFINED -2\n NOT_A_NUMBER -1\n VALUE\n PRIMITIVE\n NULL 0\n BOOLEAN 1\n NUMBER 2\n INT 2\n STRING 3\n CHAR 3\n SYMBOL 4\n OBJECT 9\n ARRAY 9\n LIST 7\n RECORD 8\n TYPE 6\n FUNCTION 5\n","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"function","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"Urtype.rank","$value$":"function (x) {\n var u = Urtype.of (x);\n switch (u) {\n case UNDEFINED : return -2;\n case NOT_A_NUMBER : return -1;\n case NULL : return 0;\n case BOOLEAN : return 1;\n case NUMBER : return 2;\n case INT : return 2;\n case STRING : return 3;\n case CHAR : return 3;\n case SYMBOL : return 4;\n case FUNCTION : return 5;\n case TYPE : return 6;\n case LIST : return 7;\n case RECORD : return 8;\n case ARRAY : return 9;\n case OBJECT : return 9;\n default : throw Error (\"Undefined urtype `\" + u + \"`.\");\n }\n}","$info$":"Urtype.rank(x)
returns the so-called an integer i
(-2 <= i <= 9
), depending on the urtype of x
, according to the following overview
urtype of `x` rank\n--------------------------- -----\nANYTHING\n IMPROPER_VALUE\n UNDEFINED -2\n NOT_A_NUMBER -1\n VALUE\n PRIMITIVE\n NULL 0\n BOOLEAN 1\n NUMBER 2\n INT 2\n STRING 3\n CHAR 3\n SYMBOL 4\n OBJECT 9\n ARRAY 9\n LIST 7\n RECORD 8\n TYPE 6\n FUNCTION 5
\n","$markdown_caption$":"global constant extensible Urtype.rank : Type.lambda ([ANYTHING, INT])","$html_caption$":"global constant extensible Urtype.rank : Type.lambda ([ANYTHING, INT])"}]],["URTYPE",{"unit":"type","name":"URTYPE","type":"TYPE","value":"new __Type ({\n complain:\n function (x) {\n if (x instanceof __Type) {\n if (List.member (Urtype.list) (x)) { return ''; }\n else { return ('The given value is a type, but not among the urtypes.'); }\n } else {\n return ('The value is no type, at all.');\n }\n },\n chi:\n function (x) {\n if (x instanceof __Type) {\n if (List.member (Urtype.list) (x)) { return true; }\n else { return false; }\n } else {\n return false;\n }\n },\n name:\n 'URTYPE',\n members:\n function () { return Urtype.list; },\n cardinality:\n function () { return Urtype.list.length; }\n})","info":"...","$unit_flags$":{"kind_of_value_unit":"static_value","type_of_value_unit":"type","scope":"global","modifiability":"constant","extensibility":"extensible","dialect":"es6","augmentation":"typed_augmentation","origin":"value_code","kind_of_unit":"value"},"$name$":"URTYPE","$value$":"new __Type ({\n complain:\n function (x) {\n if (x instanceof __Type) {\n if (List.member (Urtype.list) (x)) { return ''; }\n else { return ('The given value is a type, but not among the urtypes.'); }\n } else {\n return ('The value is no type, at all.');\n }\n },\n chi:\n function (x) {\n if (x instanceof __Type) {\n if (List.member (Urtype.list) (x)) { return true; }\n else { return false; }\n } else {\n return false;\n }\n },\n name:\n 'URTYPE',\n members:\n function () { return Urtype.list; },\n cardinality:\n function () { return Urtype.list.length; }\n})","$info$":"...
\n","$markdown_caption$":"global constant extensible URTYPE : TYPE","$html_caption$":"global constant extensible URTYPE : TYPE"}]]