"""Specify constants by a theorem, and define an overloaded constant at two types."""

from judgment import Session, forall, implies


def main() raises:
    var s = Session()
    var T = s.declare_type("T")
    var z = s.symbol("z", T)

    # A witness of the form ∀v. v = t → φ specifies a constant satisfying φ, with no equation.
    var witness = s.theorem("witness")
    var v = witness.bound_var("v", T)
    witness.goal(forall(v, implies(v == z, v == z)))
    var t = witness.tactics()
    _ = witness.by(t.intro_var("a").then(t.intro("h")).then(t.assumption()))
    var spec = s.specification(["c"], witness.finish())
    print(spec.law())

    # An overloaded constant has one opaque equation per instance.
    var header = s.overloaded("default")
    var A = header.type_var("A")
    var default = header.finish(A)
    var at_t = s.instance_definition(default, [T], z)
    print(at_t)
    print(s.instance_definition(default, [s.prop_type()], s.true_()))
    var proof = s.theorem("default_is_z", default.symbol([T]) == z)
    proof.exact(at_t)
    print(proof.finish())
