Module types

Module types 

Source
Expand description

Contains Rust functions working on types. All MeTTa specific constants are exported as a part of metta module.

To designate the atom a has a type A one need add to the space the expression (: a A). One can also assign a type to type, for example to designate A is a type add (: A Type). -> is used to create a function type, for example (: foo (-> A B)). Types can also be parameterized by type or by value. For example list of numbers can be represented as (: ns (List Number)).

There are five special meta-types: Atom, Symbol, Variable, Grounded and Expression. These types should not be assigned explicitly, but they can be used in type expressions and will be checked. For example one can define a function which accepts Atom as an argument: (: bar (-> Atom A)). When such expression is interpreted the argument is accepted without reduction (see [metta::interpreter] algorithm).

When atom has no type assigned by user it has type %Undefined%. The value of %Undefined% type can be matched with any type required.

Structs§

AtomType

Functions§

check_type
Checks if passed atom has the given typ in context of the given space. This function can be used for a simple type check when there is no need to know type parameters.
get_atom_types
Returns vector of the types for the given atom in context of the given space. Returns [%Undefined%] if atom has no type assigned.
get_meta_type
is_func
Returns true if passed type is a type of function.
match_reducted_types
Matches two types and returns an iterator over resulting bindings.
validate_atom
Returns true if atom is typed correctly. For example it can be used to check if function arguments have correct types.