Represents a type environment for parsing and type checking. Can also be
created by using the ~e sigil from ShotDs.Hol.Sigils.
Examples
iex> Context.new()
%ShotDs.Data.Context{vars: %{}, consts: %{}, constraints: MapSet.new([])}
iex> Context.new() |> Context.put_var("X", Type.new(:o))
%ShotDs.Data.Context{
vars: %{"X" => %ShotDs.Data.Type{goal: :o, args: []}},
consts: %{},
constraints: MapSet.new([])
}
Summary
Functions
Adds a type constraint to the context.
Returns the type of the given name of a constant or variable. Returns nil
if the name is not present in the context.
Creates an empty context.
Associates the constant with the given name with the given type in the context. Overwrites the old value if present.
Associates the variable with the given name with the given type in the context. Overwrites the old value if present.
Types
@type t() :: %ShotDs.Data.Context{ constraints: MapSet.t({ShotDs.Data.Type.t(), ShotDs.Data.Type.t()}), consts: %{required(String.t()) => ShotDs.Data.Type.t()}, vars: %{required(String.t()) => ShotDs.Data.Type.t()} }
The type of the type environment.
A context contains the type of variables (:vars) as a Map from its name
to its type. Likewise for the constants (:consts). The type constraints
are represented as a MapSet of ShotDs.Data.Type pairs.
Functions
@spec add_constraint(t(), ShotDs.Data.Type.t(), ShotDs.Data.Type.t()) :: t()
Adds a type constraint to the context.
@spec get_type(t(), String.t()) :: ShotDs.Data.Type.t() | nil
Returns the type of the given name of a constant or variable. Returns nil
if the name is not present in the context.
@spec new() :: t()
Creates an empty context.
@spec put_const(t(), String.t(), ShotDs.Data.Type.t()) :: t()
Associates the constant with the given name with the given type in the context. Overwrites the old value if present.
@spec put_var(t(), String.t(), ShotDs.Data.Type.t()) :: t()
Associates the variable with the given name with the given type in the context. Overwrites the old value if present.