pub enum TyDecl {
Model {
name: Arc<str>,
params: Vec<Arc<str>>,
fields: Vec<(Arc<str>, Ty)>,
},
Union {
name: Arc<str>,
params: Vec<Arc<str>>,
variants: Vec<Variant>,
},
Newtype {
name: Arc<str>,
params: Vec<Arc<str>>,
inner: Ty,
},
Alias {
name: Arc<str>,
params: Vec<Arc<str>>,
ty: Ty,
},
}Expand description
A user-declared type: a model (record), a union (ADT), a newtype, or an alias.
Comparable because a .becki interface is compared (§3.6, §4.3): two builds agree on a module’s
contract exactly when their type declarations are equal.
params is the declaration’s type-parameter names, in order — union Tree[T] has ["T"].
The names are what a .becki renders and what a doc page shows; the field types refer to the
parameters positionally through SCHEME_BASE, so a rename is a rename and nothing more.
Arity is params.len(), declared rather than inferred from use: a parameter no field mentions
is still a parameter, and Phantom[Int] and Phantom[Str] are still different types.
Variants§
Model
Union
Newtype
§3.1’s “zero-cost nominal newtype”: ids of different entities must not be interchangeable.
Alias
Implementations§
Source§impl TyDecl
impl TyDecl
pub fn name(&self) -> &Arc<str>
pub fn params(&self) -> &[Arc<str>]
Sourcepub fn param_brackets(&self) -> String
pub fn param_brackets(&self) -> String
[T, U], or the empty string when there is nothing to quantify.
Sourcepub fn as_written(&self, t: &Ty) -> Ty
pub fn as_written(&self, t: &Ty) -> Ty
One of this declaration’s field types as the declaration wrote it: the positional parameters put back under the names they were given.
Everything downstream of a TyDecl holds its parameters positionally, which is what makes
instantiation an index. Rendering is the one place that has to undo it — a .becki is
source, and value: ?1000000 is not something the parser can read back.