Type

Enum Type 

Source
pub enum Type {
    Var(TypeVar),
    Int,
    Bool,
    String,
    Unit,
    Float,
    Tuple(Vec<Type>),
    List(Box<Type>),
    Array(Box<Type>),
    Function(Box<Type>, Box<Type>),
    Record(HashMap<String, Type>),
    Variant(String, Vec<Type>),
}
Expand description

Core type representation.

Represents all types in the Fusabi type system, including:

  • Primitive types (int, bool, string, unit)
  • Composite types (tuples, lists, arrays, records)
  • Function types
  • Type variables (for inference)
  • Discriminated unions

Variants§

§

Var(TypeVar)

Type variable (e.g., ’a, ’b)

§

Int

Integer type

§

Bool

Boolean type

§

String

String type

§

Unit

Unit type ()

§

Float

Float type

§

Tuple(Vec<Type>)

Tuple type (e.g., int * string * bool)

§

List(Box<Type>)

List type (e.g., int list, ’a list)

§

Array(Box<Type>)

Array type (e.g., int[], ’a[])

§

Function(Box<Type>, Box<Type>)

Function type (e.g., int -> int, ’a -> ’b)

§

Record(HashMap<String, Type>)

Record type with named fields

§

Variant(String, Vec<Type>)

Discriminated union variant (type name, type parameters)

Implementations§

Source§

impl Type

Source

pub fn free_vars(&self) -> HashSet<TypeVar>

Get all free type variables in this type.

A free type variable is one that is not bound by any quantifier. Used for generalization and substitution.

Source

pub fn apply(&self, subst: &Substitution) -> Type

Apply a substitution to this type.

Replaces all occurrences of type variables according to the substitution.

Source

pub fn occurs_check(&self, var: &TypeVar) -> bool

Occurs check: does this type variable occur in this type?

Used to prevent infinite types during unification. Returns true if the variable appears anywhere in the type structure.

Source

pub fn function_multi(args: &[Type], ret: Type) -> Type

Helper to create a function type with multiple arguments.

Creates a right-associative chain of function types. Example: function_multi(&[int, bool], string) creates int -> bool -> string

Trait Implementations§

Source§

impl Clone for Type

Source§

fn clone(&self) -> Type

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
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

Tests for self and other values to be equal, and is used by ==.
1.0.0§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
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§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

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

§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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.
§

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

Performs the conversion.