Type Context Definition Tour
In this section, a sample type context definition will be presented line-by-line to explain how the type context works. It has been checked for consistency by the compilation software and is known to be a self-consistent type system.
Header section
A header declaration opens the type context definition. Name-value pairs of meta data are contained between the opening begin header and closing end header lines. The meta data declares the authorship, title, date of submission, etc. of the definition.
begin header
author = <<G Baran>>
author_email = <<info@eventfulstories.info>>
date = <<2025-07-29>>
title = <<Example: A Type Context Sampler>>
form = <<Text>>
language = <<English>>
content = <<
Just enough to introduce
the key elements of
Eventful Stories types and values.
>>
end header
Type definition section
After the header comes the definition of data types, opened with the begin types declaration and closed with end types..
begin types
Root declaration
root Object <<Base element of all types>>
The first type defined is the root. It specifies the name, Object, of the super-type of all super-types. The root type and primitive types have no super-type. Every general type has exactly one super-type ensuring that the type context has a simple hierarchical structure. This will be explained fully below.
All type names begin with an upper-case letter. This distinguishes them from the record field names which have lower-case names.
The text between the guillemets “<< … >>” is a comment attached to the preceding definition. Every root, primitive, type, and data field or attribute entry must have an attached descriptive comment.
Primitive types
There are four primitive data types that define the low-level constant information stored in the database directly. These are integers, real numbers, text strings, and binary-large-objects. The primitive types have no super-type.
An implementation may recognize additional primitive values for convenience, like a TimeStamp or IPv6 address.
primitive Int <<Int64>>
primitive Real <<Float>>
primitive Text <<UTF8 text>>
primitive Blob <<Binary large object>>
Defining types
Every type declaration has the form
type [Super-type name] :> [Type label]
where [Super-type name] stands for the super-type and [Type label] stands for the one-word label of the type being defined.
type :> Person <<Abstract root for a Person>>
The key word type introduces a general data type or record form or entity form. The symbol ” :>” indicates a super-type relationship.
The name of the super-type is to the left of the ” :>” symbol except for types that have the root Object as their super type, such as Person where Object is implicit and omitted.
The Person type is defined to be an abstract identity for a person. All facts about a person such as birth date or name are recorded by making a reference from the record of the fact to the abstract Person record . Person acts as an anchor for all data about a person, functioning like a Social Security Number in the US.
type Time :> Date
This statement defines a new type called Time.Date which is a sub-type of Time. The new type’s label is Date. Labels must be one capitalized word. The full name of a type is the concatenation of the label segments from root down to the type.
type :> Time <<Abstract root for an expression of time>>
type Time :> Date <<A date on a calendar>>
year :: Int <<Year>>
month :: Text <<Month name>>
day :: Int <<Day of month>>
type Time :> Instant <<Abstract root for an instant of time>>
type Time.Instant :> UTC <<Universal coordinated time>>
utc :: Blob <<An expression of universal time>>
Time is another abstract root type definition. Everything that “is-a” time is in the type hierarchy rooted at Time.
One form of a time is a date. The
type Time :> Date
line defines a new type called Time.Date that is a time. This is stated directly in the super-type relationship. That Time.Date is a sub-type of Time means that Time.Date is a specific form of a Time.
Type instantiation and UUID
When values are assigned to a type, an instance of that type is created. Each type instance is tagged with a universally unique identifier or UUID. This is the identifying hook that helps make inter-Evidence Module references work.
Attributes
Time.Date has three named fields or attributes, all of which are instantiated by constants: the year, month, and day. The double-colons “::” are common in programming languages to say “has this type’”. That is the meaning here.
Another form of a time record is a universal time or UT. This represents an instant in time expressed as a UT value, which is a sub-type of the abstract type Time.Instant, a type without any fields or attributes. The value of a UT time is recorded in the field ut as a binary value.
type :> TimePeriod <<A difference between times>>
tbegin :: Time <<Beginning time of a TimePeriod>>
tend :: Time <<Ending time of a TimePeriod>>
Closely related to a single time is a TimePeriod. It marks a time interval with a beginning and an ending time.
To express a period measured in days, for example, provide a TimePeriod instance with two Time.Date instances of Time.
Identities
type :> Identity <<A form of identity of an individual.>>
type Identity :> UUID <<A binary unique identifier for any Object.>>
uuid :: Blob <<The binary expression of the UUID>>
type Identity :> Name <<Any name>>
name :: Text <<The name of the individual>>
type Identity.Name :> Person <<A person's name>>
who :: -> Person <<Whose name>>
Forms of identity are needed for any distinguishable individuals. An identity form is a sub-type of the root type Identity.
The Identity.UUID is a universally unique identifier. Software can generate long binary patterns that have vanishingly small probabilities of being a duplicate of any other generated UUID. They are used in Eventful Stories to identify every instance of a
data type with its own set of attribute values.
A person’s name is declared to be a sub-type of an Identity.Name which contains the name. There can be all sorts of names, and the type Identity.Name.Person is the name of a person as opposed to the name of a pet or a bank.
The new element in Identity.Name.Person definition is the attribute who.
who :: -> Person <<Whose name>>
This is a pointer or reference to an existing Person entity instance. The value of such a reference in the working system is the UUID of the person.
type Comment :> Generic <<A comment on any entity in the system>>
subject :: -> Object <<Any entity can be the subject of the comment>>
Object may be used in attribute reference definitions where “any type” is allowed as a target such as for a comment type that attaches text to any object.
In the terminology of databases, the UUID identifying an entity is a primary key. A UUID in the role of a reference pointer is a foreign key. Every type in Eventful Stories functions as a separate database table, though it is not implemented as one.
When the Person UUID record is not in the Subject Evidence in the local Evidence Module, it is an external reference. The identity of an external reference is found by querying an external source for the Identity.Name.Person of “George Washington” say. The value of the who field, George Washington’s Person UUID, will be returned if found.
This example assumes that the two communicating Evidence Modules have compatible type definitions for Person and Identity. If they didn’t, an intermediate mapping between type systems would be required.
type :> Location <<Abstract root for a location>>
The Location type is the abstract root for all location values.
Layers of super-type attributes
type :> Event <<Root type for any event>>
when :: Time <<When the event occurred>>
where :: -> Location <<Where the event occurred>>
type Event :> Begin <<Abstract root for a beginning>>
type Event :> End <<Abstract root for an ending>>
type Event.Begin :> Life <<Abstract root for a birth>>
type Event.End :> Life <<Abstract root for a death>>
type Event.Begin.Life :> Person <<A person's birth>>
who :: -> Person <<Who was born>>
type Event.End.Life :> Person <<A person's death>>
who :: -> Person <<Who died>>
The Event type states that all events have data fields defining when and where the event occurred. These attributes are components of the base Event type. Every sub-type having Event in its super-type hierarchy also has the when and where attributes as a property of the super-type relation.
Sub-types add layers of every more specific information on the base. Here, a distinction between a beginning event and an ending event is expressed with the two types Event.Begin and Event.End. These types have no attributes of their own. Rather, they refine the concept of Event by creating two sub-categories.
Beginnings and endings could refer to all sorts of things: the run of a play in a theater, a work day, a lightning flash, and so on. The next level of refinement in this example is to specify beginning and ending of a life with one more layer of specification, Life: Event.Begin.Life, and Event.End.Life. No new attributes are added because these events could be about a pet, or a person, or a tree.
Adding the last refinement of Person to create types Event.Begin.Life.Person (birth) and Event.End.Life.Person (death) requires one more attribute to say who was born or died.
There are now three attributes needed to specify these final person-specific events: when, where and who. The attributes of any level in the hierarchy and all the attributes in types along the super-type path towards Object are fields required for a complete definition.
Collection types
Collection types are available for attribute values.
type :> SampleCollection <<Show the syntax for collections>>
single :: Time <<One time value>>
set :: {Time} <<Set of times (unordered, no duplicates)>>
list :: [Time] <<List of times (ordered)>>
A set consists of zero or more values of one type, Time here.
There are no duplicate values in a set, and it is unordered.
A list is a collection of of zero or more values of one type, Time here. The elements are ordered and may be any value of the indicated type.
Type definition closing
end types
Queries and presentations
As introduced in the examples of this site, simple structures can produce very rich and informative displays of evidence if the data needed exists and is organized for the purpose.
Putting the definitions of all Event types involving a Person together with the abstract identification of a Person (UUID) enables a researcher to ask about anyone:
list all the events involving person A in time order
make an animated map of the travels of person A
Imagine being able to do that.
Type-safe Database I/O
Eventful Stories software has been written in Haskell (a programming language). The implementation of Eventful Stories is type-safe throughout, including all data read and written to the database. Set or list values are serialized to the database as either a Haskell Data.Set or Data.List respectively. The Persistent and Esqueleto libraries are used for all database I/O. The ensure type-safety to and from the database. Currently supported databases are SQLite and PostgreSQL.
Type Context Consistency Rules
Some self-consistency rules govern the definition of a type context. In this list, the term “entity” has been substituted for the key word “type” as used in the type context definition to avoid ambiguity.
- The full entity name is the concatenation separated by “.” of its super-type full name and the type label of the entity
- Full entity names are unique across all root, primitive, and entity definitions
- Root and primitive types have no super type
- Every entity has exactly one super-type
- The super-type for every entity must defined within its own type context (self-consistency)
- The type labels among its immediate sub-types for any root or entity must form a set (no duplicates)
- No cycle of super-type references is permitted for any entity (prevented by requiring the termination of super-types at root)
- The attribute key names for an entity form a set (no duplicates)
- No attribute cycle following type definitions for non-reference target types (transitive closure).
- The set of attribute key names for an entity are made up of its own attribute key names and the union of the attribute key names of its super-types.
- The set of attribute key names for any entity across its super-types must be unique
Full Text of Type Context Definition
The following text is the type context definition discussed above as a continuous text block:
begin header
author = <<G Baran>>
author_email = <<info@eventfulstories.info>>
date = <<2025-07-29>>
title = <<Example: A Type Context Sampler>>
form = <<Text>>
language = <<English>>
content = <<Just enough to introduce
the key elements of
Eventful Stories types and values.
>>
end header
begin types
root Object <<Base element of all types>>
primitive Int <<Int64>>
primitive Text <<UTF8 text>>
primitive Blob <<Binary large object>>
type :> Person <<Abstract root for a Person>>
type :> Time <<Abstract root for an expression of time>>
type Time :> Date <<A date on a calendar>>
year :: Int <<Year>>
month :: Text <<Month name>>
day :: Int <<Day of month>>
type Time :> Instant <<Abstract root for an instant of time>>
type Time.Instant :> UTC <<Universal coordinated time>>
utc :: Blob <<An expression of universal time>>
type :> TimePeriod <<A difference between two times>>
tbegin :: Time <<Beginning time of a TimePeriod>>
tend :: Time <<Ending time of a TimePeriod>>
type :> Identity <<A form of identity of an individual.>>
type Identity :> UUID <<A binary unique identifier for any Object.>>
uuid :: Blob <<The binary expression of the UUID>>
type Identity :> Name <<Any name>>
name :: Text <<The name of the individual>>
type Identity.Name :> Person <<A person's name>>
who :: -> Person <<Whose name>>
type :> Location <<Abstract root for a location>>
type :> Event <<Root type for any event>>
when :: Time <<When the event occurred>>
where :: -> Location <<Where the event occurred>>
type Event :> Begin <<Abstract root for a beginning>>
type Event :> End <<Abstract root for an ending>>
type Event.Begin :> Life <<Abstract root for a birth>>
type Event.End :> Life <<Abstract root for a death>>
type Event.Begin.Life :> Person <<A person's birth>>
who :: -> Person <<Who was born>>
type Event.End.Life :> Person <<A person's death>>
who :: -> Person <<Who died>>
type :> SampleCollection <<Show the syntax for collections>>
single :: Time <<One time value>>
set :: {Time} <<Set of times (unordered, no duplicates)>>
list :: [Time] <<List of times (ordered)>>
end types
