# Modules and multiple dispatch

**URL:** <https://discourse.julialang.org/t/modules-and-multiple-dispatch/19098>\
**Category:** General Usage\
**Tags:** module\
**Created:** [December 29, 2018, 8:13pm UTC](https://discourse.julialang.org/t/modules-and-multiple-dispatch/19098 "2018-12-29T20:13:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Janis\_Erdmanis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/janis_erdmanis/32/10869_2.png) [@Janis\_Erdmanis](https://discourse.julialang.org/u/Janis_Erdmanis)\
**Post date:** [December 29, 2018, 8:13pm UTC](https://discourse.julialang.org/t/modules-and-multiple-dispatch/19098/1 "2018-12-29T20:13:14Z")

</div>

Hello everyone! I have been struggling with understanding how modules work together with multiple dispatch. What I want is to subtype abstract type defined in the module to overload specific, previously known methods. The code which shows my struggle is:

```julia
module FooTest

abstract type Foo end
foomethod(foo::Foo) = error("$(typeof(foo)) needs to implement foomethod")
hellofoo(foo::Foo) = @show foomethod(foo)

export Foo, foomethod, hellofoo
end

```

```julia
import Test: Foo, foomethod, hellofoo

### Extending Foo

struct Bar <: Foo end
foomethod(bar::Bar) = "Bar hello"

### Now testing the thing 

bar = Bar()
hellofoo(bar)

```

```julia
WARNING: could not import Test.Foo into Main
WARNING: could not import Test.foomethod into Main
WARNING: could not import Test.hellofoo into Main
ERROR: LoadError: Bar needs to implement foomethod
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] foomethod(::Bar) at /home/akels/BtSync/Projects/FooTest/src/FooTest.jl:4
 [3] macro expansion at ./show.jl:555 [inlined]
 [4] hellofoo(::Bar) at /home/akels/BtSync/Projects/FooTest/src/FooTest.jl:5
 [5] top-level scope at none:0
 [6] include at ./boot.jl:317 [inlined]
 [7] include_relative(::Module, ::String) at ./loading.jl:1044
 [8] include(::Module, ::String) at ./sysimg.jl:29
 [9] include(::String) at ./client.jl:392
 [10] top-level scope at none:0
in expression starting at /home/akels/BtSync/Projects/FooTest/test/runtests.jl:11

```

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [December 29, 2018, 8:23pm UTC](https://discourse.julialang.org/t/modules-and-multiple-dispatch/19098/2 "2018-12-29T20:23:07Z")

</div>

```julia
julia> import Test: Foo, foomethod, hellofoo
WARNING: could not import Test.Foo into Main
WARNING: could not import Test.foomethod into Main
WARNING: could not import Test.hellofoo into Main

```

These warnings are important. Your module is called `FooTest`, not `Test` (which is a stdlib module).

Edit: by the way, as a matter of style I think it’s better to use `FooTest.foomethod(bar::Bar) = "Bar hello"` rather than importing the method. Much clearer what’s going on this way.

---

<div class="post-metadata">

**Author:** ![Janis\_Erdmanis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/janis_erdmanis/32/10869_2.png) [@Janis\_Erdmanis](https://discourse.julialang.org/u/Janis_Erdmanis)\
**Post date:** [December 29, 2018, 8:28pm UTC](https://discourse.julialang.org/t/modules-and-multiple-dispatch/19098/3 "2018-12-29T20:28:49Z")

</div>

😊 That indeed was a problem in this example.
