# Creating sub types

**URL:** <https://discourse.julialang.org/t/creating-sub-types/38377>\
**Category:** New to Julia\
**Created:** [April 28, 2020, 3:21pm UTC](https://discourse.julialang.org/t/creating-sub-types/38377 "2020-04-28T15:21:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nithin\_Govindarajan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nithin_govindarajan/32/11989_2.png) [@Nithin\_Govindarajan](https://discourse.julialang.org/u/Nithin_Govindarajan)\
**Post date:** [April 28, 2020, 3:21pm UTC](https://discourse.julialang.org/t/creating-sub-types/38377/1 "2020-04-28T15:21:53Z")

</div>

I am trying to create an abstract subtype:

```julia
abstract type StructuredMatrix{T} <: AbstractMatrix{T} 

```

However when i run this line code i get: “invalid redefinition of constant”

edit: i am using juno and entering command + enter to run the lines of code

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [April 28, 2020, 3:42pm UTC](https://discourse.julialang.org/t/creating-sub-types/38377/2 "2020-04-28T15:42:20Z")

</div>

You likely defined `StructuredMatrix` previously in the same session. Redefining `structs` requires that Julia be restarted.  
(There also needs to be an `end` at the end of the definition, but I assume this is just missing from the quoted code).

---

<div class="post-metadata">

**Author:** ![Nithin\_Govindarajan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nithin_govindarajan/32/11989_2.png) [@Nithin\_Govindarajan](https://discourse.julialang.org/u/Nithin_Govindarajan)\
**Post date:** [April 28, 2020, 4:28pm UTC](https://discourse.julialang.org/t/creating-sub-types/38377/3 "2020-04-28T16:28:24Z")

</div>

Thank that seems to fix things. Still getting comforable with things.

Now that we on the topic. May I also ask why the folllowing gives me an error:

```julia
abstract type StructuredMatrix{T} <: AbstractMatrix{T} end

struct HSS{T} <: StructuredMatrix{T}

    A :: Array{T,2}

end

A = HSS{Int64}([2 2;
                4 4])

```

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [April 28, 2020, 5:22pm UTC](https://discourse.julialang.org/t/creating-sub-types/38377/4 "2020-04-28T17:22:58Z")

</div>

When you created a subtype of `AbstractMatrix` you implicitly promised that your type would support the [interface](https://docs.julialang.org/en/v1/manual/interfaces/#man-interface-array-1) of an `AbstractArray`.

When you try to `show` your `HSS` object, that promise fails and `show` tries to call a method (`size`) which is not defined for `HSS`.
