Skip to main content

Type

Enum Type 

Source
pub enum Type {
    Literal(TypeLiteral),
    Variable(TypeVariable),
    Fun {
        param_tpe: Box<Type>,
        return_tpe: Box<Type>,
    },
    Tuple(Tuple<Type>),
    Unit,
    Adt(QualName, Vec<Type>),
    Record(BTreeMap<Name, Type>),
}

Variants§

§

Literal(TypeLiteral)

§

Variable(TypeVariable)

§

Fun

Fields

§param_tpe: Box<Type>
§return_tpe: Box<Type>
§

Tuple(Tuple<Type>)

§

Unit

The unit type, (), whose one value is also written ().

A variant of its own, the way Type::Tuple is, rather than a Type::Adt known by the qualified name of a declaration the way Bool is: nothing declares (), it is a form of type expression and never a name, so there is no declaration to name and no same-spelled type it has to be told apart from. See canonical::Type::Unit.

§

Adt(QualName, Vec<Type>)

A named algebraic data type, e.g. Maybe Int declared in Maybe → Adt(Maybe.Maybe, [Literal(Int)]).

The name is the declaring package’s and module’s, in full, because that is the identity of the type: Widget.Size and Gadget.Size are two types and a value of one is never a value of the other, and so are the Size.Size of two packages. The unifier’s equality on this name is the only thing keeping them apart, so narrowing it to the spelling — which is what the typer used to carry — made every same-named declaration one type (BUG-35). Display still writes the unqualified half, since that is how a module’s source spells its own types.

§

Record(BTreeMap<Name, Type>)

A record type: each label, and the type of the field it names.

A map, for the reason canonical::Type::Record is one: a record type is a set of fields, so { x : Int, y : Int } and { y : Int, x : Int } are one value here and nothing downstream can tell the two spellings apart. The map is ordered by label, which is the order Display writes the fields in.

§How two record types unify

They unify when they carry the same set of labels and each label’s two field types unify; see unify_one_constraint. There is no row variable, and nothing ever adds a field to a record type: records are closed, so a variable only ever stands for a whole type, a record type included. Two record types with different label sets are a plain ErrorKind::UnificationFailed, and its diagnostic names the labels each side has that the other lacks (see Error’s notes).

Every walk over a type — substitution, the occurs check, instantiation, the zonk, and both renderings — goes into each field’s type as it goes into a tuple’s elements, and nothing else about a record is special to any of them.

What does not produce one is a use of a record: an access, an update or an accessor says of a type only that it has some label, and is read against a record type something else supplied — see FieldConstraint.

Trait Implementations§

Source§

impl Clone for Type

Source§

fn clone(&self) -> Type

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 Type

Source§

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

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

impl Display for Type

Writes a type the way the source would spell it, so diagnostics can quote it.

This is deliberately not Debug: Debug prints the typer’s own vocabulary (Lit(Int), Var(#3)), which is what you want at a breakpoint and never what you want in a message the user reads. Inference variables have no source syntax at all, so they are written t3 — Elm’s convention for an unsolved variable.

Source§

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

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

impl Eq for Type

Source§

impl Hash for Type

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 Type

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
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 UnsafeUnpin for Type

§

impl UnwindSafe for Type

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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
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.