Enum gluon_base::types::Type

source ·
pub enum Type<Id, T: TypePtr<Id = Id> = ArcType<Id>> {
Show 19 variants Hole, Opaque, Error, Builtin(BuiltinType), Forall(T::Generics, T), App(T, T::Types), Function(ArgType, T, T), Record(T), Variant(T), Effect(T), EmptyRow, ExtendRow { fields: T::Fields, rest: T, }, ExtendTypeRow { types: T::TypeFields, rest: T, }, Ident(KindedIdent<Id>), Projection(AppVec<Id>), Variable(TypeVariable), Generic(Generic<Id>), Alias(AliasRef<Id, T>), Skolem(Skolem<Id>),
}
Expand description

The representation of gluon’s types.

For efficiency this enum is not stored directly but instead a pointer wrapper which derefs to Type is used to enable types to be shared. It is recommended to use the static functions on Type such as Type::app and Type::record when constructing types as those will construct the pointer wrapper directly.

Variants§

§

Hole

An unbound type _, awaiting ascription.

§

Opaque

An opaque type

§

Error

A type used to mark type errors

§

Builtin(BuiltinType)

A builtin type

§

Forall(T::Generics, T)

Universally quantified types

§

App(T, T::Types)

A type application with multiple arguments. For example, Map String Int would be represented as App(Map, [String, Int]).

§

Function(ArgType, T, T)

Function type which can have a explicit or implicit argument

§

Record(T)

Record constructor, of kind Row -> Type

§

Variant(T)

Variant constructor, of kind Row -> Type

§

Effect(T)

Effect constructor, of kind Row -> Type -> Type

§

EmptyRow

The empty row, of kind Row

§

ExtendRow

Fields

§fields: T::Fields

The fields of this record type

§rest: T

The rest of the row

Row extension, of kind ... -> Row -> Row

§

ExtendTypeRow

Fields

§types: T::TypeFields

The associated types of this record type

§rest: T

The rest of the row

Row extension, of kind ... -> Row -> Row

§

Ident(KindedIdent<Id>)

An identifier type. These are created during parsing, but should all be resolved into Type::Aliases during type checking.

Identifiers are also sometimes used inside aliased types to avoid cycles in reference counted pointers. This is a bit of a wart at the moment and may cause spurious unification failures.

§

Projection(AppVec<Id>)

§

Variable(TypeVariable)

An unbound type variable that may be unified with other types. These will eventually be converted into Type::Generics during generalization.

§

Generic(Generic<Id>)

A variable that needs to be instantiated with a fresh type variable when the binding is referred to.

§

Alias(AliasRef<Id, T>)

§

Skolem(Skolem<Id>)

Implementations§

source§

impl<Id, T> Type<Id, T>
where T: TypePtr<Id = Id>,

source§

impl<Id, T> Type<Id, T>
where T: From<Type<Id, T>> + TypeExt<Id = Id>, T::Types: Default + Extend<T>,

source

pub fn hole() -> T

source

pub fn opaque() -> T

source

pub fn error() -> T

source

pub fn builtin(typ: BuiltinType) -> T

source

pub fn forall(params: Vec<Generic<Id>>, typ: T) -> T

source

pub fn array(typ: T) -> T

source

pub fn array_builtin() -> T

source

pub fn app(id: T, args: T::Types) -> T

source

pub fn variant(fields: Vec<Field<T::SpannedId, T>>) -> T

source

pub fn poly_variant(fields: Vec<Field<T::SpannedId, T>>, rest: T) -> T

source

pub fn effect(fields: Vec<Field<T::SpannedId, T>>) -> T

source

pub fn poly_effect(fields: Vec<Field<T::SpannedId, T>>, rest: T) -> T

source

pub fn tuple<S, I>(symbols: &mut S, elems: I) -> T
where S: ?Sized + IdentEnv<Ident = Id>, T::SpannedId: From<(Id, Span<BytePos>)>, I: IntoIterator<Item = T>, T: From<(Type<Id, T>, Flags)> + HasSpan,

source

pub fn tuple_<S, I>(symbols: &mut S, elems: I) -> Type<Id, T>
where S: ?Sized + IdentEnv<Ident = Id>, T::SpannedId: From<(Id, Span<BytePos>)>, I: IntoIterator<Item = T>, T: From<(Type<Id, T>, Flags)> + HasSpan,

source

pub fn record( types: Vec<Field<T::SpannedId, Alias<Id, T>>>, fields: Vec<Field<T::SpannedId, T>> ) -> T

source

pub fn poly_record( types: Vec<Field<T::SpannedId, Alias<Id, T>>>, fields: Vec<Field<T::SpannedId, T>>, rest: T ) -> T

source

pub fn extend_full_row( types: Vec<Field<T::SpannedId, Alias<Id, T>>>, fields: Vec<Field<T::SpannedId, T>>, rest: T ) -> T

source

pub fn extend_row(fields: Vec<Field<T::SpannedId, T>>, rest: T) -> T

source

pub fn extend_type_row( types: Vec<Field<T::SpannedId, Alias<Id, T>>>, rest: T ) -> T

source

pub fn empty_row() -> T

source

pub fn function<I>(args: I, ret: T) -> T
where I: IntoIterator<Item = T>, I::IntoIter: DoubleEndedIterator<Item = T>,

source

pub fn function_implicit<I>(args: I, ret: T) -> T
where I: IntoIterator<Item = T>, I::IntoIter: DoubleEndedIterator<Item = T>,

source

pub fn function_type<I>(arg_type: ArgType, args: I, ret: T) -> T
where I: IntoIterator<Item = T>, I::IntoIter: DoubleEndedIterator<Item = T>,

source

pub fn generic(typ: Generic<Id>) -> T

source

pub fn skolem(typ: Skolem<Id>) -> T

source

pub fn variable(typ: TypeVariable) -> T

source

pub fn alias(name: Id, args: Vec<Generic<Id>>, typ: T) -> T

source

pub fn alias_implicit( name: Id, args: Vec<Generic<Id>>, typ: T, is_implicit: bool ) -> T

source

pub fn ident(id: KindedIdent<Id>) -> T

source

pub fn projection(id: AppVec<Id>) -> T

source

pub fn function_builtin() -> T

source

pub fn string() -> T

source

pub fn char() -> T

source

pub fn byte() -> T

source

pub fn int() -> T

source

pub fn float() -> T

source

pub fn unit() -> T

source§

impl<Id, T> Type<Id, T>
where T: TypePtr<Id = Id>,

source

pub fn is_array(&self) -> bool

source

pub fn as_function(&self) -> Option<(&T, &T)>

source

pub fn as_explicit_function(&self) -> Option<(&T, &T)>

source

pub fn as_function_with_type(&self) -> Option<(ArgType, &T, &T)>

source

pub fn unapplied_args(&self) -> Cow<'_, [T]>
where T: Clone,

source

pub fn alias_ident(&self) -> Option<&Id>

source

pub fn applied_alias(&self) -> Option<&AliasRef<Id, T>>

source

pub fn is_non_polymorphic_record(&self) -> bool

source

pub fn params(&self) -> &[Generic<Id>]

source

pub fn kind<'k>(&'k self, cache: &'k KindCache) -> Cow<'k, ArcKind>

source§

impl<T> Type<Symbol, T>
where T: TypePtr<Id = Symbol>,

source

pub fn name(&self) -> Option<&SymbolRef>

Returns the name of self Example: Option a => Option Int => Int

source

pub fn owned_name(&self) -> Option<SymbolKey>

Trait Implementations§

source§

impl<'ast, Id, T> AstClone<'ast, Id> for Type<Id, T>
where Id: AstClone<'ast, Id> + Clone, T: AstClone<'ast, Id> + TypePtr<Id = Id>, T::Generics: AstClone<'ast, Id>, T::Types: AstClone<'ast, Id>, T::Fields: AstClone<'ast, Id>, T::TypeFields: AstClone<'ast, Id>,

source§

fn ast_clone(&self, arena: ArenaRef<'_, 'ast, Id>) -> Self

source§

impl<Id> Borrow<Type<Id>> for ArcType<Id>

source§

fn borrow(&self) -> &Type<Id, ArcType<Id>>

Immutably borrows from an owned value. Read more
source§

impl<Id: Clone, T: Clone + TypePtr<Id = Id>> Clone for Type<Id, T>
where T::Generics: Clone, T::Types: Clone, T::Fields: Clone, T::TypeFields: Clone,

source§

fn clone(&self) -> Type<Id, T>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<Id: Debug, T: Debug + TypePtr<Id = Id>> Debug for Type<Id, T>
where T::Generics: Debug, T::Types: Debug, T::Fields: Debug, T::TypeFields: Debug,

source§

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

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

impl<Id, T> Default for Type<Id, T>
where T: TypePtr<Id = Id>,

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de, Id, T> DeserializeState<'de, Seed<Id, T>> for Type<Id, T>
where T: Clone + TypePtr<Id = Id> + From<Type<Id, T>> + Any + DeserializeState<'de, Seed<Id, T>>, T::Types: Default + Extend<T>, T::Generics: Default + Extend<Generic<Id>> + Clone, T::Fields: DeserializeState<'de, Seed<Id, T>>, T::TypeFields: DeserializeState<'de, Seed<Id, T>>, Id: DeserializeState<'de, Seed<Id, T>> + Clone + Any,

source§

fn deserialize_state<__D>( __seed: &mut Seed<Id, T>, __deserializer: __D ) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserializes Self using seed and the deserializer
source§

impl<Id> From<Type<Id>> for ArcType<Id>
where Id: PartialEq,

source§

fn from(typ: Type<Id, ArcType<Id>>) -> ArcType<Id>

Converts to this type from the input type.
source§

impl<Id: Hash, T: Hash + TypePtr<Id = Id>> Hash for Type<Id, T>
where T::Generics: Hash, T::Types: Hash, T::Fields: Hash, T::TypeFields: Hash,

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<Id: PartialEq, T: PartialEq + TypePtr<Id = Id>> PartialEq for Type<Id, T>

source§

fn eq(&self, other: &Type<Id, T>) -> 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<Id, T> SerializeState<SeSeed> for Type<Id, T>

source§

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

Serializes self
source§

impl<Id: Eq, T: Eq + TypePtr<Id = Id>> Eq for Type<Id, T>
where T::Generics: Eq, T::Types: Eq, T::Fields: Eq, T::TypeFields: Eq,

source§

impl<Id, T: TypePtr<Id = Id>> StructuralEq for Type<Id, T>

source§

impl<Id, T: TypePtr<Id = Id>> StructuralPartialEq for Type<Id, T>

Auto Trait Implementations§

§

impl<Id, T> RefUnwindSafe for Type<Id, T>

§

impl<Id, T> Send for Type<Id, T>
where Id: Send + Sync, T: Send + Sync, <T as TypePtr>::Fields: Send, <T as TypePtr>::Generics: Send + Sync, <T as TypePtr>::TypeFields: Send, <T as TypePtr>::Types: Send,

§

impl<Id, T> Sync for Type<Id, T>
where Id: Send + Sync, T: Send + Sync, <T as TypePtr>::Fields: Sync, <T as TypePtr>::Generics: Send + Sync, <T as TypePtr>::TypeFields: Sync, <T as TypePtr>::Types: Sync,

§

impl<Id, T> Unpin for Type<Id, T>
where Id: Unpin, T: Unpin, <T as TypePtr>::Fields: Unpin, <T as TypePtr>::Generics: Unpin, <T as TypePtr>::TypeFields: Unpin, <T as TypePtr>::Types: Unpin,

§

impl<Id, T> UnwindSafe for Type<Id, T>

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<Id> AsId<Id> for Id
where Id: ?Sized,

source§

fn as_id(&self) -> &Id

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
§

impl<T> CallHasher for T
where T: Hash + ?Sized,

§

fn get_hash<H, B>(value: &H, build_hasher: &B) -> u64
where H: Hash + ?Sized, B: BuildHasher,

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,

§

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

impl<T> Any for T
where T: Any,

§

impl<T> CloneAny for T
where T: Any + Clone,