Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking if a model implements a theory leads to MethodNotFound error #174

Open
kris-brown opened this issue Dec 8, 2024 · 1 comment · May be fixed by #175
Open

Checking if a model implements a theory leads to MethodNotFound error #174

kris-brown opened this issue Dec 8, 2024 · 1 comment · May be fixed by #175
Assignees
Labels
bug Something isn't working

Comments

@kris-brown
Copy link
Collaborator

GATlab's approach to runtime checking if a model implements a theory is to use dispatch on ScopeTags.

F = FinMatC{Float64}()
implements(F, ThCategory) # true
implements(F, ThNat) # MethodNotFound error

A method is created by @instance to return something (not true, but something that's not nothing) for a given model type + ScopeTag (wrapped in a Val) for each scope of the theory.

I believe the line

implements(m::Module, ::Type{Val{tag}}) where {tag} = nothing

was intended to be the catch-all case for when a scope is not implemented. However, this line never gets called (perhaps Module was meant to be Model?) Trying to make a simple fix there causes other problems which will need to be debugged.

@kris-brown kris-brown self-assigned this Dec 8, 2024
@kris-brown kris-brown added the bug Something isn't working label Dec 8, 2024
@kris-brown
Copy link
Collaborator Author

kris-brown commented Dec 9, 2024

Even though there is a workaround #175, I suspect that dispatch isn't the best way to check this. I envision a solution like

implements(model::Any, theory::Union{Module,GAT}, x::Ident, types::Vector{Type})

E.g. implements(FinMatC{Int}(), ThCategory, compose, [Int, Matrix{Int}]) which the above function converts into a runtime check whether or not there is a method compose(::WithModel{FinSetC}, ::Matrix{Int}, ::Matrix{Int}).

We can then add sugar which takes a Symbol rather than an Ident(if this is not ambiguous) and uses [Any, Any,...] for the type vector if none is explicitly provided. And not providing a particular ident means the conjunction of checking all the idents in the theory.

This seems nicer than the current approach because

  1. it avoids a proliferation of implements methods (for every model type + theory scope pair)
  2. it gives you finer granularity to check if particular methods are implemented rather than only checking entire theories (or, at best, scopes)
  3. it gives you the argument type granularity to see that FinMatC{Int}() implements compose(::Matrix{Int}, ::Matrix{Int}) but not compose(::Matrix{Float64}, ::Matrix{Float64}).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant