Wikifunctions:Type proposals/Context

From Wikifunctions

Summary

The meaning of a value or object depends on its Context.

In Wikifunctions, an object’s Context is a series of Typed lists, and a Contextualized object is a Typed pair (Z882) consisting of an object and its Context.

Uses

When an object is validated, the validating function can add itself to the object’s validation context.

If an object is determined to be a member of a particular subset of the set of which it is known to be a member, the type reference can be added to the object’s reference context.

When a sequence of operations is performed, successive transformations can be included in the Context of the evaluated object (as with validations).

Structure

Initially, a Context object consists of two Typed lists:

  1. A list of Functions (typically validations and type transformations, including syntactic and semantic transformations)
  2. A list of References (typically refinements in a subtype hierarchy, or multiple inheritance).

Example values

Value 0

{
  "type": "natural number",
  "value": "0"
}
{
  "Z1K1": "Z10",
  "Z10K1": "0"
}


Persistent objects

None.

Validator

The validator ensures that:

Identity

Two … are the same if

…the following copied from Wikifunctions:Type proposals/Typed string some of it will be relevant after a complete re-write…

Identity, equality, compatibility and equivalence

Identity

Two Typed string objects are the same (“identical”) if they have the same string type reference and subtype function, as well as the same typed string value. This is “Typed string identity”. If all pairs of values differ, the Typed strings are fully distinct.

Where only one or two pairs of values match, different types of similarity apply.

Equality

Where only the typed string values match, there is mere string equality (Z866). String equality can also exist between Typed strings and other types of string, notably Z6/string and Z9/reference.

Compatibility

In the case of string inequality, if the values for subtype function are the same, the Typed strings are considered “compatible”, in the sense that they are members of the same set implied by the validation they have in common (if not of any subset thereof). Compatibility is contextual, however.

Equal values for string type reference indicate membership of the same set or subset (still assuming string inequality).

Equivalence

…In the general case, “equivalence” depends on context. If two Typed strings have equal typed string values but are not identical, they are equivalent in some contexts but not in all contexts.
…a Validator (function) is not strictly a subtype function, since it does not have a Boolean return type. This is conveniently ignored for the time being!

For example, [“42”, natural number, is a natural number] is equivalent to a Z10/natural number representation of 42 ({"Z1K1": "Z10", "Z10K1": "42"}} and [“Z10”, Z9, Z109] is equivalent to {"Z1K1": "Z9", "Z9K1": "Z10"} (a Z9/reference to the Z10/natural number Z4/type).

String equivalence means that any Z6/string can also be represented as a Typed string [Z6K1, Z6, Z106].

{
  "type": "typed string",
  "typed string value": "O",
  "string type reference": "string",
  "subtype function": "is a valid string"
}
{
  "Z1K1": "Z96",
  "Z96K1": "O",
  "Z96K2": "Z6",
  "Z96K3": "Z106" //or Boolean wrapper
}
…This means, for example, that 

[“O”, element symbol, is uppercase] is not the same as [“O”, uppercase letter, is uppercase].

…Where two string type references are “compatible” (they share a common supertype), the subtype string objects need to be converted to a supertype that they have in common before typed string identity can be tested. Since all Z96/typed strings ultimately have Z6/string as a common supertype, converting them to that type will always be an option (?and may be default behaviour if string equality (Z866) is called). In practice, “conversion” may simply mean ignoring or discarding the string type reference and the subtype function (reference).

Converting to code

Python

JavaScript

Renderer

Renderers are the responsibility of the community.


They output

Parsers

Parsers are the responsibility of the community.


Alternatives

Comments

This idea occurred to me as I was nearing the end (I thought) of the Typed string proposal. “Maybe the subtype function should be a list; maybe the string type reference should be too?”--GrounderUK (talk) 15:17, 3 March 2024 (UTC)[reply]