iter 22b.2.1: add Constraint struct, Type::Forall.constraints
This commit is contained in:
@@ -331,6 +331,21 @@ pub struct InstanceMethod {
|
||||
pub body: Term,
|
||||
}
|
||||
|
||||
/// Iter 22b.2: a class constraint on a polymorphic function (Decision
|
||||
/// 11). `(class, type)` pair where `class` is a class name and `type`
|
||||
/// is a `Type` expression — typically a single `Type::Var` (e.g.
|
||||
/// `(Eq, a)` for `Eq a => ...`). Concrete-type constraints are legal
|
||||
/// schema-wise but fired as `no-instance` at typecheck time if no
|
||||
/// matching registry entry exists.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Constraint {
|
||||
/// Class name.
|
||||
pub class: String,
|
||||
/// Type the class is applied to.
|
||||
#[serde(rename = "type")]
|
||||
pub type_: Type,
|
||||
}
|
||||
|
||||
/// A constant (top-level binding to a value).
|
||||
///
|
||||
/// Differs from a zero-arg [`FnDef`] in that it is evaluated once and
|
||||
@@ -588,6 +603,12 @@ pub enum Type {
|
||||
/// names, instantiated fresh at each use site.
|
||||
Forall {
|
||||
vars: Vec<String>,
|
||||
/// Iter 22b.2: class constraints quantified together with
|
||||
/// `vars`. Empty for pre-22b.2 polymorphic types; serialised
|
||||
/// with `skip_serializing_if = "Vec::is_empty"` so existing
|
||||
/// canonical-JSON bytes stay bit-identical.
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
constraints: Vec<Constraint>,
|
||||
body: Box<Type>,
|
||||
},
|
||||
}
|
||||
@@ -742,9 +763,9 @@ impl PartialEq for Type {
|
||||
}
|
||||
(Type::Var { name: a }, Type::Var { name: b }) => a == b,
|
||||
(
|
||||
Type::Forall { vars: a, body: ab },
|
||||
Type::Forall { vars: b, body: bb },
|
||||
) => a == b && ab == bb,
|
||||
Type::Forall { vars: a, constraints: ac, body: ab },
|
||||
Type::Forall { vars: b, constraints: bc, body: bb },
|
||||
) => a == b && ac == bc && ab == bb,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user