Package hydra.graph
Class Primitive
- java.lang.Object
-
- hydra.graph.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPrimitive.BuilderA fluent builder forPrimitive.
-
Field Summary
Fields Modifier and Type Field Description PrimitiveDefinitiondefinitionThe host-independent declarative metadata for the primitive: name, description, signature, totality and purity flags, and an optional reference implementation.static NameDEFINITIONName of thehydra.graph.Primitive.definitionfield.java.util.function.Function<Graph,java.util.function.Function<java.util.List<Term>,Either<Error_,Term>>>implementationA 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.static NameIMPLEMENTATIONName of thehydra.graph.Primitive.implementationfield.static NameTYPE_Name of thehydra.graph.Primitivetype.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Primitive.Builderbuilder()Creates a new fluent builder forPrimitive.intcompareTo(Primitive other)booleanequals(java.lang.Object other)inthashCode()java.lang.StringtoString()PrimitivewithDefinition(PrimitiveDefinition definition)Returns a copy of thisPrimitivewithdefinitionreplaced.PrimitivewithImplementation(java.util.function.Function<Graph,java.util.function.Function<java.util.List<Term>,Either<Error_,Term>>> implementation)Returns a copy of thisPrimitivewithimplementationreplaced.
-
-
-
Field Detail
-
TYPE_
public static final Name TYPE_
Name of thehydra.graph.Primitivetype.
-
DEFINITION
public static final Name DEFINITION
Name of thehydra.graph.Primitive.definitionfield.
-
IMPLEMENTATION
public static final Name IMPLEMENTATION
Name of thehydra.graph.Primitive.implementationfield.
-
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 immutablePrimitive.- 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:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
compareTo
public int compareTo(Primitive other)
- Specified by:
compareToin interfacejava.lang.Comparable<Primitive>
-
withDefinition
public Primitive withDefinition(PrimitiveDefinition definition)
Returns a copy of thisPrimitivewithdefinitionreplaced.
-
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 thisPrimitivewithimplementationreplaced.
-
builder
public static Primitive.Builder builder()
Creates a new fluent builder forPrimitive.
-
-