ToolCall.TypeExpr.Projection (ToolCall v0.4.0)

Copy Markdown

Exact set operations on ToolCall.TypeExpr, used to lower intersections and negations before they reach ToolCall.IR.Type.

JSON Schema cannot carry an arbitrary intersection or complement, so each operation either returns a value that is exactly the intersection (or difference) or reports :error. A caller that receives :error must degrade explicitly rather than approximate the type — silently widening to anyOf or any would tell the model the wrong contract.

Supported exactly today:

  • :any and :none identities
  • integer ranges and integer(), including disjoint ranges (an empty intersection, and a difference that splits into at most two ranges)
  • {:literal, value} against literals and enums
  • enums against enums
  • maps whose fields and additional properties can be merged
  • identical nodes

Summary

Functions

Intersects two type expressions.

Subtracts right from left, producing the type of values in left that are not in right.

Types

result()

@type result() :: {:ok, ToolCall.TypeExpr.t()} | :error

Functions

intersect(left, right)

@spec intersect(ToolCall.TypeExpr.t(), ToolCall.TypeExpr.t()) :: result()

Intersects two type expressions.

A {:negation, inner} operand is handled as a difference, so atom() and not nil lowers without ever emitting a JSON Schema not.

subtract(left, right)

@spec subtract(ToolCall.TypeExpr.t(), ToolCall.TypeExpr.t()) :: result()

Subtracts right from left, producing the type of values in left that are not in right.