Skip to content

Latest commit

 

History

History
161 lines (115 loc) · 4.68 KB

types.md

File metadata and controls

161 lines (115 loc) · 4.68 KB

A Type System for Actor Programming

The concept of Type in a programming language expresses a set of constraints on a value. A Value may have several "is-a" relationships with various types, indicating that value is an acceptable substitute for a placeholder of that type. A Type may also have several "is-a" relationships with other types. The "is-a" relationship is a directed acyclic graph.

Basic Types

The JSON standard describes a set of six basic data-types that have proven to be valuable for information exchange. We will start by organizing that set into a hierarchy of disjoint sub-types. Each sub-type has an "is-a" relationship with its super-type. This partitioning will form the basis for describing more complex types. The initial hierarchy looks like this:

  • Value
    • Object
      • Boolean
        • true
        • false
      • Number
      • String
      • Sequence
      • Dictionary
    • Nothing
      • null

Naming types can be quite challenging, as many different names have been used historically to denote the same semantic type. For example, JSON uses Array and Object where we have used Sequence and Dictionary.

Value

Value is the top of the hierarchy. Every Value is either an Object or Nothing.

Object

An Object is-a Value that denotes Something (as opposed to Nothing).

Nothing

Nothing is-a Value that denotes the lack of an Object. The concrete Value null is the sole instance of the Nothing type.

Boolean

A Boolean is-a Object that denotes a Boolean logical value. The concrete Values true and false are the only two instances of the Boolean type.

Number

A Number is-a Object that denotes a mathematical numeric value. There are many sub-types of Number, many of which overlap each other, while partitioning numbers in different ways. JSON encodes exact decimal values of arbitrary (but finite) size and precision.

String

A String is-a Object that denotes a finite sequence of Unicode code-points (characters).

Sequence

A Sequence is-a Object that denotes a finite sequence of Values.

Dictionary

A Dictionary is-a Object that denotes a finite association between Strings (keys) and Values. [[Q: What about non-String keys?]]

Representations

There is often confusion between the sub-typing "is-a" relationship and the "represents" relationship between values. For example, JSON describes the "represents" relationship between Unicode strings (code-point sequences) and the six basic data-types that may be "encoded" in JSON. This is not a sub-type (or substitutability) relationship. It is a transformation from one value to another.

Computational Types

The Basic Types from JSON all denote immutable data values. Several additional types of Objects may arise during computation. Some of these may have Representations in terms of the Basic Types, which implies an additional layer of translation/interpretation. Some important Computational Types include:

  • Actor
    • Function
  • Behavior
  • Message

Actor

An Actor is-a Object that designates the capability to send a Message. Values of this type are opaque, but may be compared for identity. Making a copy does not duplicate the Actor, only the Capability to send it a message. For transport, the Capability can be represented by a specially-encoded String.

Function

A Function is-a Actor that performs a transformation from a domain value to a range value. The types of the domain and range may be different. The Function is represented by an Actor with a restricted protocol. In the simplest case, the restricted protocol entails that:

  • Each message includes a customer
  • Each message results in exactly one message to the customer
  • Equal messages (excluding the customer) produce equal results

Behavior

A Behavior is-a Object that describes the Effects of an Actor handling a Message.

Message

A Message is-a Value sent to an Actor to invoke the actor's Behavior, causing some (possibly empty) set of Effects.

Abstract Data Types

Bitvector

A Bitvector is-a Object that denotes a finite sequence of Boolean values. For transport, a Bitvector can be represented by an arbitrary-precision Integer Number.

Blob

A Blob is-a Object that denotes a finite sequence of Byte values (Integer Numbers in the range [0, 255]). For transport, a Blob can be represented by a String, with code-points restricted to the Byte range.

Extended Types

Stream

Sum Type

Product Type