Enum erg_compiler::ty::typaram::TyParam
source · pub enum TyParam {
Show 16 variants
Value(ValueObj),
Type(Box<Type>),
Array(Vec<TyParam>),
Tuple(Vec<TyParam>),
Set(Set<TyParam>),
Dict(Dict<TyParam, TyParam>),
Record(Dict<Field, TyParam>),
Lambda(TyParamLambda),
Mono(Str),
Proj {
obj: Box<TyParam>,
attr: Str,
},
App {
name: Str,
args: Vec<TyParam>,
},
UnaryOp {
op: OpKind,
val: Box<TyParam>,
},
BinOp {
op: OpKind,
lhs: Box<TyParam>,
rhs: Box<TyParam>,
},
Erased(Box<Type>),
FreeVar(FreeTyParam),
Failure,
}
Expand description
type parameter
Unevaluated expressions that types can have inside
The evaluated one becomes ValueObj
.
- Literal: 1, “aa”, True, None, … (don’t use container literals, they can only hold literals)
- Type: Int, Add(?R, ?O), …
- Mono: I, N, …
- Attr: math.PI, …
- Array:
[1, 2, N]
- Tuple: (1, N, True)
- App: Array(Int), Fib(10), …
- QuantVar: N: Nat, …
- FreeVar: ?I: Int, …
- UnaryOp: -N, ~B, …
- BinOp: 1 + 1, N * 2, …
- Erased: _: Type, _: Nat, …
Variants§
Value(ValueObj)
Type(Box<Type>)
Array(Vec<TyParam>)
Tuple(Vec<TyParam>)
Set(Set<TyParam>)
Dict(Dict<TyParam, TyParam>)
Record(Dict<Field, TyParam>)
Lambda(TyParamLambda)
Mono(Str)
Proj
App
UnaryOp
BinOp
Erased(Box<Type>)
FreeVar(FreeTyParam)
Failure
Implementations§
source§impl TyParam
impl TyParam
pub fn t(t: Type) -> Self
pub fn mono<S: Into<Str>>(name: S) -> Self
pub fn mono_q<S: Into<Str>>(name: S, constr: Constraint) -> Self
pub fn proj<S: Into<Str>>(self, attr: S) -> Self
pub fn proj_call(self, attr_name: Str, args: Vec<TyParam>) -> Type
pub fn free_var(level: usize, t: Type) -> Self
pub fn named_free_var(name: Str, level: usize, constr: Constraint) -> Self
sourcepub fn value<V: Into<ValueObj>>(v: V) -> Self
pub fn value<V: Into<ValueObj>>(v: V) -> Self
NOTE: Always add postfix when entering numbers. For example, value(1)
will be of type Int.
pub fn unary(op: OpKind, val: TyParam) -> Self
pub fn mutate(self) -> Self
pub fn bin(op: OpKind, lhs: TyParam, rhs: TyParam) -> Self
pub fn app(name: &'static str, args: Vec<TyParam>) -> Self
pub fn erased(t: Type) -> Self
pub fn succ(self) -> Self
pub fn pred(self) -> Self
pub fn qual_name(&self) -> Option<Str>
pub fn tvar_name(&self) -> Option<Str>
pub fn cheap_cmp(&self, r: &TyParam) -> Option<TyParamOrdering>
pub fn coerce(&self)
pub fn qvars(&self) -> Set<(Str, Constraint)>
pub fn has_qvar(&self) -> bool
pub fn contains_tvar(&self, target: &FreeTyVar) -> bool
pub fn contains(&self, target: &Type) -> bool
pub fn is_unbound_var(&self) -> bool
pub fn has_unbound_var(&self) -> bool
pub fn has_no_unbound_var(&self) -> bool
pub fn has_upper_bound(&self) -> bool
pub fn has_lower_bound(&self) -> bool
pub fn replace(self, target: &Type, to: &Type) -> TyParam
Trait Implementations§
source§impl CanbeFree for TyParam
impl CanbeFree for TyParam
fn unbound_name(&self) -> Option<Str>
fn constraint(&self) -> Option<Constraint>
fn update_constraint(&self, new_constraint: Constraint, in_instantiation: bool)
source§impl From<RangeInclusive<&TyParam>> for TyParam
impl From<RangeInclusive<&TyParam>> for TyParam
source§fn from(r: RangeInclusive<&TyParam>) -> Self
fn from(r: RangeInclusive<&TyParam>) -> Self
Converts to this type from the input type.
source§impl From<RangeInclusive<TyParam>> for TyParam
impl From<RangeInclusive<TyParam>> for TyParam
source§fn from(r: RangeInclusive<TyParam>) -> Self
fn from(r: RangeInclusive<TyParam>) -> Self
Converts to this type from the input type.