mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 04:09:05 +00:00
feat: support refinement class
This commit is contained in:
parent
c72de02c2c
commit
678c02faf9
9 changed files with 94 additions and 4 deletions
|
@ -133,6 +133,28 @@ pub fn singleton(ty: Type, tp: TyParam) -> Type {
|
|||
|
||||
#[inline]
|
||||
pub fn int_interval<P, PErr, Q, QErr>(op: IntervalOp, l: P, r: Q) -> Type
|
||||
where
|
||||
P: TryInto<TyParam, Error = PErr>,
|
||||
PErr: fmt::Debug,
|
||||
Q: TryInto<TyParam, Error = QErr>,
|
||||
QErr: fmt::Debug,
|
||||
{
|
||||
interval(op, Type::Int, l, r)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn closed_range<P, PErr, Q, QErr>(t: Type, l: P, r: Q) -> Type
|
||||
where
|
||||
P: TryInto<TyParam, Error = PErr>,
|
||||
PErr: fmt::Debug,
|
||||
Q: TryInto<TyParam, Error = QErr>,
|
||||
QErr: fmt::Debug,
|
||||
{
|
||||
interval(IntervalOp::Closed, t, l, r)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn interval<P, PErr, Q, QErr>(op: IntervalOp, t: Type, l: P, r: Q) -> Type
|
||||
where
|
||||
P: TryInto<TyParam, Error = PErr>,
|
||||
PErr: fmt::Debug,
|
||||
|
@ -161,7 +183,7 @@ where
|
|||
Predicate::le(name.clone(), r),
|
||||
),
|
||||
IntervalOp::Open if l == TyParam::value(NegInf) && r == TyParam::value(Inf) => {
|
||||
return refinement(name, Type::Int, Predicate::TRUE)
|
||||
return refinement(name, t, Predicate::TRUE)
|
||||
}
|
||||
// l<..<r => {I: classof(l) | I >= l+ε and I <= r-ε}
|
||||
IntervalOp::Open => Predicate::and(
|
||||
|
@ -169,7 +191,7 @@ where
|
|||
Predicate::le(name.clone(), TyParam::pred(r)),
|
||||
),
|
||||
};
|
||||
refinement(name, Type::Int, pred)
|
||||
refinement(name, t, pred)
|
||||
}
|
||||
|
||||
pub fn iter(t: Type) -> Type {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue