Skip to content

feature: add flag, typing to DblTheory to match RFC-0001#1145

Open
tslil-topos wants to merge 1 commit intomainfrom
tslil/push-ryxqzzpnwqxk
Open

feature: add flag, typing to DblTheory to match RFC-0001#1145
tslil-topos wants to merge 1 commit intomainfrom
tslil/push-ryxqzzpnwqxk

Conversation

@tslil-topos
Copy link
Collaborator

@tslil-topos tslil-topos commented Mar 19, 2026

The particular interpretation of that RFC here is as follows:

  • constraint: change no code outside of the theory definitions
  • constraint: allow users of the DblTheory trait to depend on the type system to know whether hom_types are always present
  • implementation trick: "shallow" dependant typing, fn hom_type(&self, x: Self::ObType) -> <Self::Kind as DblTheoryKind>::Wrap<Self::MorType>;
    • when DblTheoryKind is Categorical, Wrap = Id, when it's SetTheoretic, Wrap = Option

Notes:

  • there was a blanket implementation of DblTheory from VDCWithComposites. This has been macro-ised as imlp_dbl_theory, relaxed from blanket to allow more flexible use
  • the error messages in hom_op were slightly more informative, distinguishing self.unit_ext(y) from self.through_unit(cell, 0) failures, now these failures are not distiguished
  • docstrings may need more work to adhere to the high standards we have already

Several other design approaches were weighed and dismissed:

  • BaseDlbTheory with sub traits DblTheory and SetTheoreticDblTheory: introduces more code, more concepts to juggle, lots of duplication
  • hom_type returns Option always, with flag on impl: no type system guarantees, adds .unwrap() boilerplate to call sites, forces us to specialise the blanket implementation anyway
  • DblTheory<Categorical> and DblTheory<SetTheoretic> as separate traits: loss of ergonomics at call sites, would be two copies of every method, Rust doesn't pick for you
  • UnitalDblTheory supertrait with user contracts: still not strong enough guarantee, have to update call sites

Closes #1099

The particular interpretation of that RFC here is as follows:
* constraint: change no code outside of the theory definitions
* constraint: allow users of the DblTheory trait to depend on the type system to know whether hom_types are always present
* implementation trick: "shallow" dependant typing, `fn hom_type(&self, x: Self::ObType) -> <Self::Kind as DblTheoryKind>::Wrap<Self::MorType>;`
  * when DlTheoryKind is Categorical, Wrap = Id, when it's SetTheoretic, Wrap = Option

Notes:
* there was a blanket implementation of DblTheory from VDCWithComposites. This has been macro-ised as `imlp_dbl_theory`, relaxed from blanket to allow more flexible use
* the error messages in hom_op were slightly more informative, distinguishing self.unit_ext(y) from self.through_unit(cell, 0) failures, now these failures are not distiguished

Several other design approaches were weighed and dismissed:
* BaseDlbTheory with sub traits DblTheory and SetTheoreticDblTheory: introduces more code, more concepts to juggle, lots of duplication
* hom_type returns Option always, with flag on impl: no type system guarantees, adds .unwrap() boilerplate to call sites, forces us to specialise the blanket implementation anyway
* DblTheory<Categorical> and DblTheory<SetTheoretic> as separate traits: loss of ergonomics at call sites, would be two copies of every method, Rust doesn't pick for you
* UnitalDblTheory supertrait with user contracts: still not strong enough guarantee, have to update call sites
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow for non-unital double theories

1 participant