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
impl Type
Sourcepub fn free_vars(&self) -> HashSet<TypeVar>
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.
Sourcepub fn apply(&self, subst: &Substitution) -> Type
pub fn apply(&self, subst: &Substitution) -> Type
Apply a substitution to this type.
Replaces all occurrences of type variables according to the substitution.
Sourcepub fn occurs_check(&self, var: &TypeVar) -> bool
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.
Sourcepub fn function_multi(args: &[Type], ret: Type) -> Type
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)