Documentation

Transfer.Deriving.ParamCongr

derive_param_congr — a constructor-congruence Related deriver #

The Related kernel (Transfer/Base/Related.lean) auto-composes binary-op trees on a single carrier (composeBinOp over RelatedBinOp squares) but stops at any structure head: it provides no constructor congruence for user inductives. Crossing a structure boundary (e.g. a value of a single-constructor structure that encodes to the product of its fields) therefore needs, per type, one product-encoding enc plus one constructor-congruence Related instance — the Param_<T> boilerplate.

This file generates that boilerplate. It is the Trocq/Elpi Param_<T> analogue for the Related kernel: a metaprogram that, for a single-constructor structure T, reads the constructor's field names and types and emits

With both registered, instance resolution transports a structured value compositionally — the constructor congruence on top, the base-carrier RelatedBinOp squares underneath — with no monolithic whole-op leaf.

Surface #

Both route to the same generator, deriveParamCongrCore.

Reflective-vs-assumed boundary #

1. The field-encoding typeclass #

ParamEnc A α: a registered encoding A → α for the structure-field recursion. The derived ParamEnc T _ instance for a structure encodes it to the product of its fields' encodings, so the recursion is automatic.

  • enc : A → α

    The encoding map.

Instances
    @[instance_reducible, instance 100]

    Leaf. An atomic type encodes to itself by id. Low priority so a derived structure instance (default priority) wins when both could apply.

    Equations
    @[instance 100]
    instance Transfer.Deriving.relatedBinOpOfLeaf {A : Type} (op bop : A → A → A) [h : RelatedBinOp id op bop] :

    Bridge. Any base-carrier RelatedBinOp registered at the id encoding lifts to the ParamEnc-leaf encoding for free (ParamEnc.enc at a leaf type is definitionally id). One instance re-uses every id-registered op square under the derived congruence — no per-op boilerplate.

    @[instance 100]

    Leaf-encoding Related. a transports to itself along the ParamEnc leaf (it is id). Gives the base case of the congruence's per-coordinate composition an RHS that is literally the input (not ParamEnc.enc a), so composeBinOp terminates cleanly at base-carrier variables.

    Marker class keying the deriving handler (deriving instance ParamCongr for T). The handler generates the ParamEnc/Related instances and ignores the literal class.

      Instances

        2. The generator #

        Build the anonymous tuple syntax (x₀, …, xₙ₋₁) (right-nested Prod.mk); a singleton is returned bare.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For

          Build the right-nested product type syntax x₀ × … × xₙ₋₁; a singleton is returned bare.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For

            The core generator: read single-constructor structure declName and emit its ParamEnc product-encoding instance and its constructor-congruence Related instance.

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For

              3. Surfaces #

              In-file command: derive_param_congr T.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                Equations
                • One or more equations did not get rendered due to their size.
                Instances For

                  The registered deriving handler (deriving instance ParamCongr for T). Single-constructor structures only; declines otherwise so another handler can take over.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For