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