Note that this can be made to work by tearing a page from Base:  we can a 
module (SuperSecretBase), that defines a stub value() function. We then use 
importall SuperSecretBase in each of Foo and Bar.    But this means that 
any module we create would need to declare its functions into 
SuperSecretBase.

julia> workspace() ; include("mike.jl")

julia> using Foo

julia> using Bar

julia> value(Bar.BarType())
"Bar::value"

julia> value(Foo.FooType())
"Foo::value"

julia> 

Modified code follows: 

module SuperSecretBase
value() = nothing
export value
end

# ------------------------------

module Foo

importall SuperSecretBase

importall Base
type FooType end

value(x::FooType) = "Foo::value"
get(x::FooType) = "Foo::get"

export value

end

# ------------------------------

module Bar

importall SuperSecretBase

importall Base

type BarType end

value(x::BarType) = "Bar::value"
get(x::BarType) = "Bar::get"

export value

end




On Tuesday, April 21, 2015 at 9:26:01 AM UTC-4, Michael Turok wrote:
>
> Hi,
>
> What is the idiomatic way to create a function value() in different 
> modules, dispatched on different arguments, without getting the 
> warning/error about conflicting with an existing identifier?
>
> It seems like there is an order dependency with the example below.   Seems 
> like the 2nd module defines value(), unless you had already used value() 
> prior to importing the 2nd module.   
>
> Note that if I do the same with get() a function defined in Base, I don't 
> get an error. 
>
> Code and output from julia REPL below.
>
> Any help appreciated,
> Michael
>
> # this is mike.jl
>
> # ------------------------------
> module Foo
> # ------------------------------
> importall Base
> type FooType end
>
> value(x::FooType) = "Foo::value"
> get(x::FooType) = "Foo::get"
>
> export value
>
> end
>
> # ------------------------------
> module Bar
> # ------------------------------
> importall Base
>
> type BarType end
>
> value(x::BarType) = "Bar::value"
> get(x::BarType) = "Bar::get"
>
> export value
>
> end
>
> Using this in the REPL: 
> julia> workspace() ; include("mike.jl")
>
> julia> using Foo
>
> julia> value(Foo.FooType())
> "Foo::value"
>
> julia> using Bar
> Warning: using Bar.value in module Main conflicts with an existing 
> identifier.
>
> julia> value(Bar.BarType())
> ERROR: `value` has no method matching value(::BarType)
>
> # -----------------------------------------------------
>
> julia> workspace() ; include("mike.jl")
>
> julia> using Foo
>
> julia> using Bar
>
> julia> value(Foo.FooType())
> ERROR: `value` has no method matching value(::FooType)
>
> julia> value(Bar.BarType())
> "Bar::value"
>
> # -----------------------------------------------------
>
> julia> workspace() ; include("mike.jl")
>
> julia> using Bar
>
> julia> using Foo
>
> julia> value(Foo.FooType())
> "Foo::value"
>
> julia> value(Bar.BarType())
> ERROR: `value` has no method matching value(::BarType)
>
> julia> 
>

Reply via email to