Skip to main content

Module synth

Module synth 

Source
Expand description

Type Synthesis for Eure Documents

This module infers types from Eure document values without requiring a schema. The synthesized types can be used for:

  • Generating schema definitions from example data
  • Type checking across multiple files
  • Editor tooling (hover types, completions)

§Example

use eure_document::document::{EureDocument, NodeId};
use eure_schema::synth::{synth, SynthType};

let doc = eure!({ name = "Alice", age = 30 });
let ty = synth(&doc, doc.get_root_id());
// ty = Record { name: Text, age: Integer }

§Unification

When synthesizing arrays, element types are unified:

// [ { a = 1 }, { a = "x", b = "y" } ]
// Result: Array<{ a: Integer } | { a: Text, b: Text }>

Holes are absorbed during unification:

// [1, !, 3]
// Result: Array<Integer>  (not Array<Integer | Hole>)

Structs§

SynthField
A field in a record type
SynthRecord
A record type with named fields
SynthUnion
A structural union of types

Enums§

SynthType
A synthesized type inferred from document values.

Functions§

synth
Synthesize a type from a document node.
unify
Unify two types into their least upper bound.