Skip to content

Explicit models which just use type dispatch #176

@kris-brown

Description

@kris-brown

Interoperability between the old style of GATlab and the new one has been limited to creating models. One can create an old-style one (where implementation is just dictated by dispatch) by not providing a [model::MyModel] in the @instance declaration.

However, if one is consuming models, such as a function f(some_ThCategory_model, some_ThMonoid_model) then this can really only ever use the new GATlab models, since there's no reified thing to plug in which says "just use type dispatch".

However, GATlab could define a struct Dispatch end along with

Base.getindex(f, ::Dispatch) = f

So that compose[myDispatchModel](f::GATExpr, g::GATExpr) would just evaluate to whatever type dispatch says compose(f::GATExpr, g::GATExpr) should do. This is relevant to Catlab, where we want to use infrastructure which expects explicit models on the result of @symbolic_model, which currently just produces an old-style instance.

For a related and slightly different problem: consider that one might have a model (e.g. struct CatC which implements ThCategory with Category and Functor), and it's already the case that ThCategory.dom(::Functor), ThCategory.id(::Category), etc. are all defined. Here it would be convenient to have a macro which says "CatC should just use dispatch to implement ThCategory" rather than writing out a bunch of boilerplate. It could look like this:

@default_model ThCategory{Category, Functor} [model::CatC]

Couldn't you just use cat = Dispatch(ThCategory, [Category, Functor]) instead of cat = CatC()?

No: maybe CatC implements some other theories (e.g. Th2Category) in different ways that will not be implemented by mere dispatch.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions