Enum erg_compiler::ty::typaram::TyParam
source · pub enum TyParam {
Show 19 variants
Value(ValueObj),
Type(Box<Type>),
Array(Vec<TyParam>),
UnsizedArray(Box<TyParam>),
Tuple(Vec<TyParam>),
Set(Set<TyParam>),
Dict(Dict<TyParam, TyParam>),
Record(Dict<Field, TyParam>),
DataClass {
name: Str,
fields: Dict<Field, TyParam>,
},
Lambda(TyParamLambda),
Mono(Str),
Proj {
obj: Box<TyParam>,
attr: Str,
},
ProjCall {
obj: Box<TyParam>,
attr: Str,
args: Vec<TyParam>,
},
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>)
UnsizedArray(Box<TyParam>)
Tuple(Vec<TyParam>)
Set(Set<TyParam>)
Dict(Dict<TyParam, TyParam>)
Record(Dict<Field, TyParam>)
DataClass
Lambda(TyParamLambda)
Mono(Str)
Proj
ProjCall
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: Str, args: Vec<TyParam>) -> Self
pub fn range(start: Self, end: Self) -> Self
pub fn free_instance(level: usize, t: Type) -> Self
pub fn free_var(level: usize, constr: Constraint) -> 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 bin(op: OpKind, lhs: TyParam, rhs: TyParam) -> Self
pub fn app(name: Str, args: Vec<TyParam>) -> Self
pub fn erased(t: Type) -> Self
pub fn unsized_array(elem: TyParam) -> Self
pub fn succ(self) -> Self
pub fn pred(self) -> Self
pub fn qual_name(&self) -> Option<Str>
pub fn local_name(&self) -> Option<Str>
pub fn tvar_name(&self) -> Option<Str>
pub fn cheap_cmp(&self, r: &TyParam) -> Option<TyParamOrdering>
pub fn destructive_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_type(&self, target: &Type) -> bool
pub fn contains_tp(&self, target: &TyParam) -> bool
pub fn is_recursive(&self) -> 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_undoable_linked_var(&self) -> bool
pub fn union_size(&self) -> usize
pub fn has_upper_bound(&self) -> bool
pub fn has_lower_bound(&self) -> bool
pub fn is_erased(&self) -> bool
pub fn is_type(&self) -> bool
pub fn substitute(self, var: &str, to: &TyParam) -> TyParam
pub fn replace(self, target: &TyParam, to: &TyParam) -> TyParam
pub fn replace_t(self, target: &Type, to: &Type) -> TyParam
pub fn typarams(&self) -> Vec<TyParam>
pub fn contained_ts(&self) -> Set<Type>
pub fn dereference(&mut self)
pub fn namespace(&self) -> Str
pub fn variables(&self) -> Set<Str>
Trait Implementations§
source§impl CanbeFree for TyParam
impl CanbeFree for TyParam
fn unbound_name(&self) -> Option<Str>
fn constraint(&self) -> Option<Constraint>
fn destructive_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.
source§impl LimitedDisplay for TyParam
impl LimitedDisplay for TyParam
source§impl PartialEq for TyParam
impl PartialEq for TyParam
source§impl StructuralEq for TyParam
impl StructuralEq for TyParam
fn structural_eq(&self, other: &Self) -> bool
source§impl<'t> TryFrom<&'t TyParam> for &'t FreeTyParam
impl<'t> TryFrom<&'t TyParam> for &'t FreeTyParam
impl Eq for TyParam
Auto Trait Implementations§
impl RefUnwindSafe for TyParam
impl Send for TyParam
impl Sync for TyParam
impl Unpin for TyParam
impl UnwindSafe for TyParam
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more