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

WithModel dispatch is too strict, ought accept subtypes #169

Open
kris-brown opened this issue Dec 7, 2024 · 0 comments · May be fixed by #170
Open

WithModel dispatch is too strict, ought accept subtypes #169

kris-brown opened this issue Dec 7, 2024 · 0 comments · May be fixed by #170
Assignees
Labels
enhancement New feature or request

Comments

@kris-brown
Copy link
Collaborator

kris-brown commented Dec 7, 2024

GATlab does a trick where it converts a (literally) indexed function, e.g. compose[myCat](f,g), into something Julia can dispatch on: compose(WithModel{MyCat}(myCat), f, g). This latter method is programmatically generated by @instance, but this generated method expects (TheoryInterface.WithModel){$model_type}. This is too strict: rather it ought accept (TheoryInterface.WithModel){<:$model_type}. For example, if model_type is an abstract type, then any particular model one passes will only be a subtype, not an exact match. See below for an example:

""" Assume this implements Base.iterate """
abstract type MyAbsIter{V} <: Model{Tuple{V}} end

struct MyVect{V} <: MyAbsIter{V}
  v::Vector{V}
end

Base.iterate(m::MyVect, i...) = iterate(m.v, i...)

@instance ThSet{V} [model::MyAbsIter{V}] where V begin 
  default(v::V) = v  model ? v : @fail "Bad $v not in $model"
end

@test implements(MyVect([1,2,3]), ThSet)

# this will fail unless WithModel accepts subtypes
@test ThSet.default[MyVect([1,2,3])](1) == 1
@kris-brown kris-brown added the enhancement New feature or request label Dec 7, 2024
@kris-brown kris-brown self-assigned this Dec 7, 2024
@kris-brown kris-brown linked a pull request Dec 7, 2024 that will close this issue
@kris-brown kris-brown linked a pull request Dec 7, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant