View Source Guesswork.Ast.Entity protocol (Guesswork v0.8.0)

An entity is a concrete value or set of possible values (plural type) that can be bound to a variable or included as an argument to a Guesswork.Ast.Fact.

Summary

Types

t()

All the types that implement this protocol.

Functions

Compares two entities.

Display the entity for the result set.

Merge two entities have the same negation. Note that they do not need to have the same type. For instance, a plural type can be compared to a single type (in that argument order) and should return the single type if it is a member of the plural type. This generally requires using the implementation of the plural type.

Indicates if the entity represents multiple possible values or a single definate value. Note that the merge/2 implementation of plural entities will always be prefered.

Allows a user to traverse an entity. Mostly used for plural values that are Enumerable. Concrete values should just wrap themselves in a list.

Types

t()

@type t() :: term()

All the types that implement this protocol.

Functions

compare(vala, valb)

@spec compare(t(), t()) :: t() | :lt | :gt | :neq

Compares two entities.

Note that there may be an implicit assignment (followed by merge) durring an commparision. This is why instead of :eq an entity canidate is returned. This canidate may be 'smaller' than the inputs, allowing a better value to be bound.

Plural values are also why :neq may be returned. For instance, consider the sets [1, 4, 5] and [2, 3, 6]. There is clearly no instance where these sets are equal, but you can not say one will always be less or greater than the other.

display(entity)

@spec display(t()) :: String.t()

Display the entity for the result set.

merge(vala, valb)

@spec merge(t(), t()) :: t() | nil

Merge two entities have the same negation. Note that they do not need to have the same type. For instance, a plural type can be compared to a single type (in that argument order) and should return the single type if it is a member of the plural type. This generally requires using the implementation of the plural type.

plural?(entity)

@spec plural?(t()) :: boolean()

Indicates if the entity represents multiple possible values or a single definate value. Note that the merge/2 implementation of plural entities will always be prefered.

traverse(entity)

@spec traverse(t()) :: Enumerable.t(t())

Allows a user to traverse an entity. Mostly used for plural values that are Enumerable. Concrete values should just wrap themselves in a list.