AlgebraicJulia / Catlab.jl

A framework for applied category theory in the Julia language
https://www.algebraicjulia.org
MIT License
610 stars 57 forks source link

Representing Object Hierarchies #100

Closed jpfairbanks closed 3 years ago

jpfairbanks commented 4 years ago

If we wanted to model numerical computations in Julia with Catlab, we would need to represent the type hierarchy. My first thought is to add a morphism constructor to the doctrine like subtype(A::Ob, b::Ob)::Hom(A,B) which represents the fact that if A <: B, then you can cast an instance of A to an instance of B. Is that the best way to mode “order sorted algebras” within Catlab?

epatters commented 4 years ago

Here's how I implemented order-sorted algebra, on both objects and morphisms, for the Data Science Ontology:

https://github.com/IBM/semanticflowgraph/blob/e6ddc2115c75d4563b0e84592a89c7cb7466ef0c/src/Doctrine.jl#L66

To summarize: I add GAT types for both subobjects (subtypes) and submorphisms (commutative diagrams induced by subtyping). For the subobjects, there is a term constructor coerce that yields the morphism performing the implicit conversion (or coercion), similarly to your suggested constructor subtype. The submorphisms define a 2-categorical structure, with notions of vertical and horizontal composition.