Hi,
For some reason (I know that it can be bad architecture), I need to write functions for a type that is not yet declared.
Is there a way to do this?
Hi,
For some reason (I know that it can be bad architecture), I need to write functions for a type that is not yet declared.
Is there a way to do this?
Nope. You can’t write f(x::MyType) = ... before MyType is defined.
You can, however, write f(x) = ... at any time and then pass in a MyType to f after you’ve defined MyType.
You can use abstract types to avoid needing to define fully general methods.
julia> abstract type AbstractFoo end
julia> bar(::AbstractFoo) = 3
bar (generic function with 1 method)
julia> struct Foo{T} <: AbstractFoo
x::T
end
julia> bar(Foo(2))
3
OP using Abstract types is the correct answer.