Enum cl_typeck::inference::Type

source ·
pub enum Type {
    Variable(Variable),
    Operator(Operator),
}
Expand description

A Type::Variable or Type::Operator:

  • A Type::Variable can be either bound or unbound (instance: Some(_) | None)
  • A Type::Operator has a name (used to identify the operator) and a list of types.

A type which contains unbound variables is considered “generic” (see Type::is_generic()).

Variants§

§

Variable(Variable)

§

Operator(Operator)

Implementations§

source§

impl Type

source

pub fn new_var() -> RcType

Creates a new unbound type variable

source

pub fn new_inst(of: &RcType) -> RcType

Creates a variable that is a new instance of another Type

source

pub fn new_op(name: Sym, types: &[RcType]) -> RcType

Creates a new type operator

source

pub fn new_fn(takes: &RcType, returns: &RcType) -> RcType

Creates a new type operator representing a lambda

source

pub fn new_prim(name: Sym) -> RcType

Creates a new type operator representing a primitive type

source

pub fn new_tuple(members: &[RcType]) -> RcType

Creates a new type operator representing a tuple

source

pub fn set_instance(self: &RcType, of: &RcType)

Sets this type variable to be an instance of the other

§Panics

Panics if self is not a type variable

source

pub fn is_generic(self: &RcType) -> bool

Checks whether there are any unbound type variables in this type.

let bool = Type::new_op("bool".into(), &[]);
let true_v = Type::new_inst(&bool);
let unbound = Type::new_var();
let id_fun = Type::new_fn(&unbound, &unbound);
let truthy = Type::new_fn(&unbound, &bool);
assert!(!bool.is_generic());   // bool contains no unbound type variables
assert!(!true_v.is_generic()); // true_v is bound to `bool`
assert!(unbound.is_generic()); // unbound is an unbound type variable
assert!(id_fun.is_generic());  // id_fun is a function with unbound type variables
assert!(truthy.is_generic());  // truthy is a function with one unbound type variable
source

pub fn deep_clone(self: &RcType) -> RcType

Makes a deep copy of a type expression.

Bound variables are shared, unbound variables are duplicated.

source

pub fn prune(self: &RcType) -> RcType

Returns the defining instance of self, collapsing type instances along the way.

§May panic

Panics if this type variable’s instance field is already borrowed.

§Examples
let t_bool = Type::new_op("bool".into(), &[]);
let t_nest = Type::new_inst(&Type::new_inst(&Type::new_inst(&t_bool)));
let pruned = t_nest.prune();
assert_eq!(pruned, t_bool);
assert_eq!(t_nest, Type::new_inst(&t_bool));
source

pub fn occurs_in(self: &RcType, other: &RcType) -> bool

Checks whether a type expression occurs in another type expression

§Note:
  • Since the test uses strict equality, self should be pruned prior to testing.
  • The test is not guaranteed to terminate for recursive types.
source

pub fn unify(self: &RcType, other: &RcType) -> Result<(), InferenceError>

Unifies two type expressions, propagating changes via interior mutability

Trait Implementations§

source§

impl Debug for Type

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for Type

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq for Type

source§

fn eq(&self, other: &Type) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Type

source§

impl StructuralPartialEq for Type

Auto Trait Implementations§

§

impl !Freeze for Type

§

impl !RefUnwindSafe for Type

§

impl !Send for Type

§

impl !Sync for Type

§

impl Unpin for Type

§

impl !UnwindSafe for Type

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.