Afaik there are only a couple of ways to deal with this issue:

1) Define all types beforehand, as you mention
2) Define an abstract type ahead of time that your future type is a subtype 
of.

For example:
abstract AbstractBar

type foo end

f(arg1::foo, arg2::AbstractBar)
    yadda yadda
end


type bar <: AbstractBar end

g(arg1::foo, arg2::AbstractBar)
   yadda yadda
end

You could do something analogous with foo if you wanted as well, but don't 
need to in this example. There won't be a performance penalty here because 
f and g will be compiled for specific concrete types once they are called. 
It is a little weird though if you're only ever going to have one subtype 
of AbstractBar for it to exist in the first place though.


On Friday, March 6, 2015 at 2:30:13 PM UTC-8, Kristoffer Carlsson wrote:
>
> If I have a function that uses two types as argument do I have to declare 
> both types before defining the function?
>
> I think an example will make my question clearer.
>
> Say I want the following structure of a package:
>
> #Package.jl
> module Package
> export f, g
> include("foo.jl")
> include("bar.jl")
> end
>
> #foo.jl
> type foo end
>
> f(arg1::foo, arg2::bar)
>     yadda yadda
> end
>
> #bar.jl
> type bar end
>
> g(arg1::foo, arg2::bar)
>    yadda yadda
> end
>
>
>
> This will not work because when f is declared, bar is not defined.
>
> Is there anyway I can solve this without moving both type declarations to 
> a separate file and including that first?
>

Reply via email to