# Multi-dimensional type declaration within a mutable structure

**URL:** https://discourse.julialang.org/t/multi-dimensional-type-declaration-within-a-mutable-structure/11500
**Category:** New to Julia
**Created:** [June 7, 2018, 11:44am UTC](https://discourse.julialang.org/t/multi-dimensional-type-declaration-within-a-mutable-structure/11500 "2018-06-07T11:44:15Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![drarnau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drarnau/32/4476_2.png) [@drarnau](https://discourse.julialang.org/u/drarnau)
#### Post date: [June 7, 2018, 11:44am UTC](https://discourse.julialang.org/t/multi-dimensional-type-declaration-within-a-mutable-structure/11500/1 "2018-06-07T11:44:15Z")

</div>

I’m new to Julia and I face the following issue. I try to declare a mutable structure like this:  
“”"  
mutable struct mystructname  
X::Array{Float64}(4, 4)  
end  
“”"

But the compiler does not like it:

> TypeError: mystructname: in type definition, expected Type, got Array{Float64,2}  
> include\_string(::String, ::String) at loading.jl:522  
> include\_string(::String, ::String, ::Int64) at eval.jl:30  
> include\_string(::Module, ::String, ::String, ::Int64, ::Vararg{Int64,N} where N) at eval.jl:34  
> (::Atom.##102#107{String,Int64,String})() at eval.jl:82  
> withpath(::Atom.##102#107{String,Int64,String}, ::String) at utils.jl:30  
> withpath(::Function, ::String) at eval.jl:38  
> hideprompt(::Atom.##101#106{String,Int64,String}) at repl.jl:67  
> macro expansion at eval.jl:80 [inlined]  
> (::Atom.##100#105{Dict{String,Any}})() at task.jl:80

Any ideas?

---

<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 7, 2018, 11:47am UTC](https://discourse.julialang.org/t/multi-dimensional-type-declaration-within-a-mutable-structure/11500/2 "2018-06-07T11:47:02Z")

</div>

This should work:

```julia
mutable struct MyStructName
X::Array{Float64,2}
end

```

The difference is that `Array{Float64,2}` is a type whereas `Array{Float64}(4,4)` is an instance of that type. (Also, please quote your code with back-ticks `, triple for multiline code.)

Edit: also note that types are usually in CamelCase.

---

<div class="post-metadata">

### Author: ![drarnau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drarnau/32/4476_2.png) [@drarnau](https://discourse.julialang.org/u/drarnau)
#### Post date: [June 7, 2018, 12:57pm UTC](https://discourse.julialang.org/t/multi-dimensional-type-declaration-within-a-mutable-structure/11500/3 "2018-06-07T12:57:09Z")

</div>

Thanks a lot!

I’ve tried that, but if I understand correctly `X::Array{Float64,2}` is for any 2-dimensional array, so I need to specify somewhere else in the structure that I only allow (5,5) elements, something like:

```julia
mutable struct mystructname
X::Array{Float64,2}
i,j = size(X)
    if i != 5 || j != 5
        error
    end
end

```

Does that make sense?

---

<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 7, 2018, 1:07pm UTC](https://discourse.julialang.org/t/multi-dimensional-type-declaration-within-a-mutable-structure/11500/4 "2018-06-07T13:07:05Z")

</div>

Have a read through the constructors-section in the docs. In particular this section and its example: [https://docs.julialang.org/en/stable/manual/constructors/#Inner-Constructor-Methods-1](https://docs.julialang.org/en/stable/manual/constructors/#Inner-Constructor-Methods-1)

---

<div class="post-metadata">

### Author: ![Bernard\_GODARD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bernard_godard/32/4155_2.png) [@Bernard\_GODARD](https://discourse.julialang.org/u/Bernard_GODARD)
#### Post date: [June 7, 2018, 1:10pm UTC](https://discourse.julialang.org/t/multi-dimensional-type-declaration-within-a-mutable-structure/11500/5 "2018-06-07T13:10:01Z")

</div>

If you know the size of your array you should use

> **[GitHub - JuliaArrays/StaticArrays.jl: Statically sized arrays for Julia](https://github.com/JuliaArrays/StaticArrays.jl)**
>
> Statically sized arrays for Julia. Contribute to JuliaArrays/StaticArrays.jl development by creating an account on GitHub.

If you still want to use array, you need to add your check in the constructor:

```julia
mutable struct mystructname
X::Array{Float64,2}
mystructname(x) = (size(x)!=(5,5)) ? error("invalid size") : new(x)
end

```
