# How to define a function in a different module other than what you are in right now

**URL:** <https://discourse.julialang.org/t/how-to-define-a-function-in-a-different-module-other-than-what-you-are-in-right-now/11736>\
**Category:** General Usage\
**Created:** [June 17, 2018, 8:31pm UTC](https://discourse.julialang.org/t/how-to-define-a-function-in-a-different-module-other-than-what-you-are-in-right-now/11736 "2018-06-17T20:31:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [June 17, 2018, 8:31pm UTC](https://discourse.julialang.org/t/how-to-define-a-function-in-a-different-module-other-than-what-you-are-in-right-now/11736/1 "2018-06-17T20:31:19Z")

</div>

Hi Fellows,

```nohighlight
module DDF
end

function DDF.foo(x::Int)
   x+1
end

```

i want to define a function within DDF like foo.

How can i do that? The example above doesn’t work.

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [June 17, 2018, 8:44pm UTC](https://discourse.julialang.org/t/how-to-define-a-function-in-a-different-module-other-than-what-you-are-in-right-now/11736/2 "2018-06-17T20:44:35Z")

</div>

```julia
DDF.eval(:(function foo(x::Int)
   x+1
end))

```

Note that this is usually bad style.

Better:

```julia
module DDF
function foo end # just define the generic function without any methods
end

function DDF.foo(x::Int) # add a method to DDF.foo
x+1
end

```
