pub struct Declaration {
pub name: Name,
pub arity: usize,
pub tpe: Type,
pub context: Vec<Predicate>,
pub body: Option<Body>,
pub span: NodeSpan,
}Expand description
One value of a module: what a backend emits as a named binding.
Fields§
§name: Name§arity: usizeHow many arguments a call site has to supply for the call to be a direct call.
For a declaration with a body this is the number of parameters it was written
with, which is Body::parameters’s length — not the number of arrows in its
type. f : Int -> Int -> Int written f a = add a has arity 1, and a call
supplying two arguments is one direct call followed by one partial application.
For a facade signature, which has no body to count parameters off, it is the number of arrows in the signature: the companion’s export takes a plain parameter list of exactly that length, and a signature with no arrow at all is a facade constant.
tpe: TypeThe declaration’s own type, as inference solved it — or, for a facade, as the signature declares it.
context: Vec<Predicate>What the declaration’s annotation requires of its type variables, one
Predicate per constraint written, in the order written — empty for a
declaration whose annotation has no =>, for every declaration with no
annotation, and for a facade signature.
Read off the declaration’s solved type, as the types on its nodes are: each
predicate’s type is the variable the annotation constrained. The annotation’s
variables are rigid while the body is checked, so it is always a variable of
tpe.
A superclass the context implies is not listed.
body: Option<Body>The parameters and the expression they are in scope over, for a declaration that has a body.
None is a module foreign facade’s signature. It is the whole reason this is an
Option: a facade declares what crosses the boundary and the code is in the
companion, so there is nothing here to emit and
zelkova_js::emit reads the signature
instead.
span: NodeSpanWhere the declaration was written, annotation and body together.