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
impl Ty
Sourcepub fn double_prim() -> Self
pub fn double_prim() -> Self
Creates an unboxed Double# type (64-bit float).
Sourcepub fn float_prim() -> Self
pub fn float_prim() -> Self
Creates an unboxed Float# type (32-bit float).
Sourcepub fn is_ty_list(&self) -> bool
pub fn is_ty_list(&self) -> bool
Returns true if this is a type-level list.
Sourcepub fn as_nat(&self) -> Option<&TyNat>
pub fn as_nat(&self) -> Option<&TyNat>
Returns the type-level natural if this is a Nat variant.
Sourcepub fn as_ty_list(&self) -> Option<&TyList>
pub fn as_ty_list(&self) -> Option<&TyList>
Returns the type-level list if this is a TyList variant.