The Modules documentation [1] was recently updated with a nice table that's helpful in understanding what the various using and import statements actually do. One tricky bit is that there's a difference between bringing a name into scope and making it available for method extension.
Specifically you need to add a `import SomeLibrary.bar` to main_program.jl to make it available for method extension. [1]: http://docs.julialang.org/en/latest/manual/modules/#summary-of-module-usage peace, s On Fri, Aug 1, 2014 at 2:58 PM, Dustin Lee <[email protected]> wrote: > So > > export MyType, foo, bar > > and > > using SomeLibrary > > is not enough? > > How do I change it to be more specific? > > > On Fri, Aug 1, 2014 at 12:50 PM, Jameson Nash <[email protected]> wrote: > >> Since you haven't explicitly imported MyType.bar, when you defined bar >> again, it created a new, unrelated function Main.bar, rather than merging >> them >> >> >> On Friday, August 1, 2014, Dustin Lee <[email protected]> wrote: >> >>> Given two files: >>> >>> SomeLibrary.jl >>> =============== >>> module SomeLibrary >>> >>> export MyType, foo, bar >>> >>> abstract MyType >>> >>> function bar(mt::MyType) >>> println("I'm in MyType/bar") >>> mt.x * 3 >>> end >>> >>> function foo(mt::MyType) >>> bar(mt) + 1 >>> end >>> >>> end >>> >>> >>> main_program.jl >>> =============== >>> >>> using SomeLibrary >>> >>> type NewType <: MyType >>> x >>> end >>> >>> function bar(nt::NewType) >>> println("I'm in NewType/bar") >>> nt.x * 2 >>> end >>> >>> println(foo(NewType(10))) >>> >>> >>> >>> >>> When running main_program.jl I'd expect: >>> >>> I'm in NewType/bar >>> >>> But instead I get >>> >>> I'm in MyType/bar >>> >>> So I guess my expectations are a little messed up. I'm hoping someone >>> can help me think through the logic of scoping here. >>> >>> Why isn't the more specific type function being used? >>> >>> I'm on Julia 0.3. >>> >>> thanks >>> >>> > > > -- > Dustin Lee > qhfgva=rot13(dustin) >
