Skip to main content

Ty

Enum Ty 

Source
pub enum Ty {
    Var(TyVar),
    Con(TyCon),
    Prim(PrimTy),
    App(Box<Ty>, Box<Ty>),
    Fun(Box<Ty>, Box<Ty>),
    Tuple(Vec<Ty>),
    List(Box<Ty>),
    Forall(Vec<TyVar>, Box<Ty>),
    Error,
    Nat(TyNat),
    TyList(TyList),
}
Expand description

The main type representation in BHC.

Types are represented as an algebraic data type with various constructors for different kinds of types in the Haskell type system.

Variants§

§

Var(TyVar)

A type variable (e.g., a in a -> a).

§

Con(TyCon)

A type constructor (e.g., Int, Maybe, []).

§

Prim(PrimTy)

An unboxed primitive type (e.g., Int#, Double#). Used in Numeric Profile for zero-overhead computation.

§

App(Box<Ty>, Box<Ty>)

Type application (e.g., Maybe Int, Either String).

§

Fun(Box<Ty>, Box<Ty>)

Function type (e.g., Int -> Bool). This is sugar for App(App(TyCon("->"), a), b).

§

Tuple(Vec<Ty>)

Tuple type (e.g., (Int, Bool, String)).

§

List(Box<Ty>)

List type (e.g., [Int]). This is sugar for App(TyCon("[]"), Int).

§

Forall(Vec<TyVar>, Box<Ty>)

A forall-quantified type (e.g., forall a. a -> a).

§

Error

An error type, used during type checking to allow recovery.

§

Nat(TyNat)

A type-level natural number (e.g., 1024 in Tensor '[1024] Float).

Has kind Nat. Used for tensor dimensions.

§

TyList(TyList)

A type-level list (e.g., '[1024, 768] in Tensor '[1024, 768] Float).

Has kind [Nat] when used for tensor shapes.

Implementations§

Source§

impl Ty

Source

pub fn unit() -> Self

Creates a unit type ().

Source

pub fn fun(from: Ty, to: Ty) -> Self

Creates a function type a -> b.

Source

pub fn list(elem: Ty) -> Self

Creates a list type [a].

Source

pub fn int_prim() -> Self

Creates an unboxed Int# type (64-bit signed integer).

Source

pub fn double_prim() -> Self

Creates an unboxed Double# type (64-bit float).

Source

pub fn float_prim() -> Self

Creates an unboxed Float# type (32-bit float).

Source

pub fn is_prim(&self) -> bool

Returns true if this is an unboxed primitive type.

Source

pub fn as_prim(&self) -> Option<PrimTy>

Returns the primitive type if this is a Prim variant.

Source

pub fn is_fun(&self) -> bool

Returns true if this is a function type.

Source

pub fn is_error(&self) -> bool

Returns true if this is an error type.

Source

pub fn free_vars(&self) -> Vec<TyVar>

Returns the free type variables in this type.

Source

pub fn is_ground(&self) -> bool

Returns true if this type contains no unification variables.

Source

pub fn nat_lit(n: u64) -> Self

Creates a type-level natural literal.

Source

pub fn shape(dims: &[u64]) -> Self

Creates a shape type from dimension values.

Source

pub fn is_nat(&self) -> bool

Returns true if this is a type-level natural.

Source

pub fn is_ty_list(&self) -> bool

Returns true if this is a type-level list.

Source

pub fn as_nat(&self) -> Option<&TyNat>

Returns the type-level natural if this is a Nat variant.

Source

pub fn as_ty_list(&self) -> Option<&TyList>

Returns the type-level list if this is a TyList variant.

Trait Implementations§

Source§

impl Clone for Ty

Source§

fn clone(&self) -> Ty

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Ty

Source§

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

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

impl<'de> Deserialize<'de> for Ty

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Ty

Source§

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

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

impl Eq for Ty

Source§

impl Hash for Ty

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Ty

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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 Serialize for Ty

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Ty

Auto Trait Implementations§

§

impl Freeze for Ty

§

impl RefUnwindSafe for Ty

§

impl Send for Ty

§

impl Sync for Ty

§

impl Unpin for Ty

§

impl UnsafeUnpin for Ty

§

impl UnwindSafe for Ty

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> CloneToUninit for T
where T: Clone,

Source§

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

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

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

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

Source§

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>,

Source§

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>,

Source§

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.