My apologies! I was writing on my phone so I couldn’t test.
module M2
# We need to make sure the datetime function type exists in M2 first
function datetime end
module M1
# the bring it into scope of M1
import ..datetime
export MyModel
abstract type MyModel end
Base.isless(x::MyModel, y::MyModel) = datetime(x) < datetime(y)
end
using .M1
struct MyChild <: MyModel
datetime
end
datetime(C::MyChild) = C.datetime
MyChild(1) < MyChild(2)
end
OR if you prefer to have M1 own datetime then
module M2
module M1
export MyModel
function datetime end
abstract type MyModel end
Base.isless(x::MyModel, y::MyModel) = datetime(x) < datetime(y)
end
using .M1
struct MyChild <: MyModel
datetime
end
M1.datetime(C::MyChild) = C.datetime
MyChild(1) < MyChild(2)
end
Which one doesn’t work? Both? Could you give the full stack trace so I can see where it’s erroring? I had it working on my side, so I’m wondering if I copied and pasted it incorrectly or something.