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
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
@type concrete_id() :: atom()
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 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).
@type variable_id() :: reference()
Functions
@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.
@spec fresh_type_var() :: t()
Creates a fresh variable for a simple type using Erlang references.
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.
Checks whether the given type or type identifier is a type variable.