The TypeChecker performs semantic validation on AXON programs using an epistemic type system. Unlike traditional type checkers that focus on memory layout, AXON’s type checker validates the nature and reliability of information.
from axon import Lexer, Parser, TypeCheckersource = '''persona Expert { domain: ["medicine"] confidence_threshold: 1.5 # ERROR: must be 0.0-1.0}flow Analyze(doc: UnknownType) -> String { # ERROR: UnknownType not defined step Process { ask: "Process the document" }}'''lexer = Lexer(source)parser = Parser(lexer.tokenize())ast = parser.parse()checker = TypeChecker(ast)errors = checker.check()for error in errors: print(f"Line {error.line}: {error.message}")
checker = TypeChecker(ast)# Check if source type can be used where target type is expectedcan_use = checker.check_type_compatible( source="CitedFact", target="FactualClaim")print(can_use) # True (CitedFact is a subtype of FactualClaim)can_use = checker.check_type_compatible( source="Opinion", target="FactualClaim")print(can_use) # False (Opinion cannot be used as FactualClaim)
source = '''run AnalyzeContract(contract) as UnknownPersona # Error: persona not defined within UnknownContext # Error: context not defined constrained_by [NoHallucination, UnknownAnchor] # Error: anchor not defined effort: ultra # Error: unknown effort level'''
from axon import AxonTypeErrorclass AxonTypeError: message: str line: int column: int
Example:
try: errors = checker.check() if errors: for error in errors: print(f"Type error at {error.line}:{error.column}") print(f" {error.message}")except Exception as e: print(f"Unexpected error: {e}")
# Undefined type referenceerrors = checker.check() # "Type 'MyCustomType' is not defined"# Invalid epistemic coercionerrors = checker.check()# "Cannot use Opinion where FactualClaim is expected"# Range constraint violationerrors = checker.check()# "confidence_threshold must be between 0.0 and 1.0, got 1.5"# Duplicate declarationerrors = checker.check()# "Duplicate declaration: 'Expert' already defined as persona"