TypeCheck v0.2.0 TypeCheck.Type View Source
TODO
Link to this section Summary
Types
Indicates that we expect a 'type AST' that will be expanded
to a proper type. This means that it might contain essentially the full syntax that Elixir Typespecs
allow, which will be rewritten to calls to the functions in TypeCheck.Builtin
.
Something is a TypeCheck.Type if it implements the TypeCheck.Protocols.ToCheck protocol.
Functions
Constructs a concrete type from the given type_ast
.
Link to this section Types
Specs
expandable_type() :: any()
Indicates that we expect a 'type AST' that will be expanded
to a proper type. This means that it might contain essentially the full syntax that Elixir Typespecs
allow, which will be rewritten to calls to the functions in TypeCheck.Builtin
.
See TypeCheck.Builtin
for the precise syntax you are allowed to use.
Specs
t() :: any()
Something is a TypeCheck.Type if it implements the TypeCheck.Protocols.ToCheck protocol.
It is also expected to implement the TypeCheck.Protocols.Inspect protocol (although that has an Any
fallback).
In practice, this type means 'any of the' structs in the TypeCheck.Builtin.*
modules.
Link to this section Functions
Constructs a concrete type from the given type_ast
.
This means that you can pass type-syntax to this macro,
which will be transformed into explicit calls to the functions in TypeCheck.Builtin
.
iex> res = TypeCheck.Type.build(:ok | :error)
iex> res
#TypeCheck.Type< :ok | :error >
iex> # This is the same as:
iex> import TypeCheck.Builtin, only: [one_of: 2, literal: 1]
iex> explicit = one_of(literal(:ok), literal(:error))
iex> res == explicit
true
iex> res = TypeCheck.Type.build({a :: number(), b :: number()} when a <= b)
iex> res
#TypeCheck.Type< ({a :: number(), b :: number()} when a <= b) >
iex> # This is the same as:
iex> import TypeCheck.Builtin, only: [fixed_tuple: 1, number: 0, guarded_by: 2, named_type: 2]
iex> explicit = guarded_by(fixed_tuple([named_type(:a, number()), named_type(:b, number())]), quote do a <= b end)
iex> explicit
#TypeCheck.Type< ({a :: number(), b :: number()} when a <= b) >
Of course, you can refer to your own local and remote types as well.