# Import struct to module

**URL:** <https://discourse.julialang.org/t/import-struct-to-module/14385>\
**Category:** New to Julia\
**Created:** [August 31, 2018, 9:24pm UTC](https://discourse.julialang.org/t/import-struct-to-module/14385 "2018-08-31T21:24:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elmer\_Cusipuma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elmer_cusipuma/32/11958_2.png) [@Elmer\_Cusipuma](https://discourse.julialang.org/u/Elmer_Cusipuma)\
**Post date:** [August 31, 2018, 9:24pm UTC](https://discourse.julialang.org/t/import-struct-to-module/14385/1 "2018-08-31T21:24:58Z")

</div>

I am trying to create modules that contains functions and structs

```julia
struct coord{T,N}
    x::T 
    y::N
end 

module A
function ms(pt::coord)
    println(pt.x)
end
end

```

Getting this error when I run test

`UndefVarError: coord not defined`

How to import `coord` in a module?

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [August 31, 2018, 10:02pm UTC](https://discourse.julialang.org/t/import-struct-to-module/14385/2 "2018-08-31T22:02:57Z")

</div>

You should define Coord inside the same module, or else define it in a separate module and then do using or import to import that module.

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [August 31, 2018, 10:28pm UTC](https://discourse.julialang.org/t/import-struct-to-module/14385/3 "2018-08-31T22:28:02Z")

</div>

> [@Elmer\_Cusipuma](#):
>

Here is an example of David’s note.

```julia
julia> module Coordinates

       export Coord, distance_from_origin
       #=
            The parameter `T` will be replaced by the type
            used to hold the values of `x` and `y`. 
            Presumably, you want the `x` and `y` of one coordinate
            to share a single type (maybe Float64 or Int32).

            When you construct an actual Coord with Float64 values,
            this happens:

            julia> point = Coord(1.0, 3.0)
            Coord(1.0, 3.0)
            julia> point.y
            3.0
       =#
       struct Coord{T}
           x::T 
           y::T 
       end 

       function distance_from_origin(point::Coord{T}) where {T}
           return sqrt(point.x * point.x + point.y * point.y)
       end

end # module Coordinates
Main.Coordinates

```

Now you can use what you have placed in that module.  
(note that when using a module you typed into the interactive shell, you say:  
`using .Coordinates` but when using a module that is a saved package, you say:  
`using Coordinates` without the `dot`).

```julia
julia> using .Coordinates

julia> point = Coord(4.0, 2.0)
Coord{Float64}(4.0, 2.0)

julia> point.x, point.y
(4.0, 2.0)

julia> distance_from_origin(point)
4.47213595499958

```
