pub enum TypeExpr {
Fun {
opts: Vec<OptArrowDom>,
dom: TypeProd,
arrow: ArrowTok,
cod: Box<TypeExpr>,
},
Atom(TypeProd),
OptRowFun {
opt_dom: CstTypeOptDom,
dom: TypeProd,
arrow: ArrowTok,
cod: Box<TypeExpr>,
},
}Expand description
A minimal type-expression grammar for type declarations and
signature (val .. : ty) annotations (txfunc/txprod/txapppre/
txapp/txbot, simplified). Function arrows (right-associative,
with an optional-argument ?-> prefix chain — see OptArrowDom),
2+-way product types (*, TypeProd), a SINGLE-argument postfix
type-constructor application ('a option, 'a list; see
TypeApp), command-argument-list types ([ty; ty?; ..] inline-cmd/block-cmd/math-cmd; see TypeAtom::Cmd),
parenthesized grouping, closed record types ((| l : ty; … |); see
TypeAtom::Record), bare/qualified names, and type variables are
supported; N-ary applied constructors are not — such input is
rejected with a parse error. Self-recursive only through Fun’s
codomain (right recursion); parenthesized nesting goes through the
super::TyErased leaf.
Variants§
Fun
opts?-> dom -> cod (right-associative). dom is a TypeProd
(not just TypeAtom) so e.g. 'a option -> 'b option and 'a * 'b -> 'c both parse at their expected precedence (application
binds tighter than *, which binds tighter than ->). opts is
upstream’s txfuncopts prefix (parser.mly:880-882): zero or
more ty ?-> domains greedily consumed before the final
mandatory dom -> cod, e.g. config ?-> block-text -> document
parses as opts = [config], dom = block-text, cod = document. Lowered (typecheck.rs) to an option-wrapped
mandatory domain per optional entry — see that module’s doc
comment on lower_type_expr.
Atom(TypeProd)
The non-arrow fallthrough. Despite the name (kept stable — see
the module’s compile-time-blowup note on why every recursion
edge here is deliberate), this holds a full TypeProd, not a
bare TypeAtom: a product/application with no enclosing arrow
is still just “the whole type expression minus ->”.
OptRowFun
?(l1 : ty1, …) dom -> cod — a SATySFi 0.1 labeled-optional
function TYPE domain (upstream typ’s second production,
parser_v1.mly:688-691). Lowered
(typecheck.rs) to MonoType::Func(Row::Cons(l1, ty1, … Row::Empty), dom, cod) — a CLOSED row, matching what
Ast::LambdaOpt infers, so an explicit ?(l:τ)->
signature unifies against an actual ?(l=x)-taking function.
?-headed — token-disjoint from Fun/Atom (neither
TypeProd nor TypeAtom can start with OptionalTypeTok),
so declared order is safety-neutral; appended last, this file’s
convention for 0.1 additions. It widens the 0.0.6 ACCEPT surface:
a 0.0.6 program containing ?(l : int) -> int parses here and
reaches typecheck.rs::lower_type_expr’s version gate, which
rejects it under V0_0 with a version-error message (better
diagnostics than a parse error).
Trait Implementations§
Source§impl<__SyanMacro_Atom> Parse<__SyanMacro_Atom> for TypeExpr
impl<__SyanMacro_Atom> Parse<__SyanMacro_Atom> for TypeExpr
Source§type Error = <TypeExpr as ParseRanked8909385c15d27adc<(((),),), __SyanMacro_Atom>>::Error
type Error = <TypeExpr as ParseRanked8909385c15d27adc<(((),),), __SyanMacro_Atom>>::Error
<FieldTy as Parse<Atom>>::Error: Into<…> predicate re-creates a projection cycle on a
recursive field (E0275), which decycle’s bound-peeling does not break.