Package hydra.graph

Class Primitive

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<Primitive>

    public class Primitive
    extends java.lang.Object
    implements java.io.Serializable, java.lang.Comparable<Primitive>
    A built-in function or constant, consisting of the host-independent PrimitiveDefinition (name, signature, metadata) plus a host-specific implementation.
    See Also:
    Serialized Form
    • Field Detail

      • TYPE_

        public static final Name TYPE_
        Name of the hydra.graph.Primitive type.
      • DEFINITION

        public static final Name DEFINITION
        Name of the hydra.graph.Primitive.definition field.
      • IMPLEMENTATION

        public static final Name IMPLEMENTATION
        Name of the hydra.graph.Primitive.implementation field.
      • definition

        public final PrimitiveDefinition definition
        The host-independent declarative metadata for the primitive: name, description, signature, totality and purity flags, and an optional reference implementation.
      • implementation

        public final java.util.function.Function<Graph,​java.util.function.Function<java.util.List<Term>,​Either<Error_,​Term>>> implementation
        A concrete, host-specific implementation of the primitive function: given the current graph, a mapping from a list of argument terms to a result term, or an error. Arguments are reduced and stripped of annotations by the interpreter before the implementation is invoked, so the implementation can pattern-match the argument terms directly; a higher-order primitive whose result shape is fixed by its data argument can return an unreduced applicative term and let the outer reducer fold it (no graph needed). The graph is retained for the higher-order primitives that must evaluate a function argument mid-computation (e.g. lists.filter): evaluating that function resolves primitive names against the graph's primitive table. The legacy `InferenceContext` parameter was vestigial and has been removed (https://github.com/CategoricalData/hydra/issues/446).
    • Constructor Detail

      • Primitive

        public Primitive​(PrimitiveDefinition definition,
                         java.util.function.Function<Graph,​java.util.function.Function<java.util.List<Term>,​Either<Error_,​Term>>> implementation)
        Constructs an immutable Primitive.
        Parameters:
        definition - The host-independent declarative metadata for the primitive: name, description, signature, totality and purity flags, and an optional reference implementation.
        implementation - A concrete, host-specific implementation of the primitive function: given the current graph, a mapping from a list of argument terms to a result term, or an error. Arguments are reduced and stripped of annotations by the interpreter before the implementation is invoked, so the implementation can pattern-match the argument terms directly; a higher-order primitive whose result shape is fixed by its data argument can return an unreduced applicative term and let the outer reducer fold it (no graph needed). The graph is retained for the higher-order primitives that must evaluate a function argument mid-computation (e.g. lists.filter): evaluating that function resolves primitive names against the graph's primitive table. The legacy `InferenceContext` parameter was vestigial and has been removed (https://github.com/CategoricalData/hydra/issues/446).
    • Method Detail

      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • compareTo

        public int compareTo​(Primitive other)
        Specified by:
        compareTo in interface java.lang.Comparable<Primitive>
      • withImplementation

        public Primitive withImplementation​(java.util.function.Function<Graph,​java.util.function.Function<java.util.List<Term>,​Either<Error_,​Term>>> implementation)
        Returns a copy of this Primitive with implementation replaced.