ShotDs.Data.Type (shot_ds v1.1.2)

Copy Markdown View Source

Provides a data structure for Church's simple types (monotypes).

Examples

iex> o = Type.new(:o)
%ShotDs.Data.Type{goal: :o, args: []}

iex> io = Type.new(:o, :i)
%ShotDs.Data.Type{goal: :o, args: [%ShotDs.Data.Type{goal: :i, args: []}]}

iex> Type.new(io, [o, :o])
%ShotDs.Data.Type{
  goal: :o,
  args: [
    %ShotDs.Data.Type{goal: :i, args: []},
    %ShotDs.Data.Type{goal: :o, args: []},
    %ShotDs.Data.Type{goal: :o, args: []}
  ]
}

Summary

Types

t()

The type of a simple type.

The type of a basic type.

Functions

Returns the set of type variable references appearing anywhere in the given type. Used by the type inference engine for generalization.

Creates a fresh variable for a simple type using Erlang references.

Creates a new simple type. Optionally, a list of arguments can be specified.

Checks whether the given type or type identifier is a type variable.

Types

concrete_id()

@type concrete_id() :: atom()

t()

@type t() :: %ShotDs.Data.Type{args: [t()], goal: type_id()}

The type of a simple type.

The goal can be a concrete name for the type like :i or :o or a reference denoting a type variable. The arguments of a type are a list of simple types.

Note that this is an uncurried representation of higher-order types.

type_id()

@type type_id() :: concrete_id() | variable_id()

The type of a basic type.

A basic type is identified as an atom (concrete type) or a reference (type variable).

variable_id()

@type variable_id() :: reference()

Functions

free_type_vars(type)

@spec free_type_vars(t()) :: MapSet.t(variable_id())

Returns the set of type variable references appearing anywhere in the given type. Used by the type inference engine for generalization.

fresh_type_var()

@spec fresh_type_var() :: t()

Creates a fresh variable for a simple type using Erlang references.

new(goal, args \\ [])

@spec new(type_id() | t(), type_id() | t() | [type_id() | t()]) :: t()

Creates a new simple type. Optionally, a list of arguments can be specified.

Behaves as identity function on a single argument representing a simple type.

type_var?(type)

@spec type_var?(t() | type_id()) :: boolean()

Checks whether the given type or type identifier is a type variable.