# How is Matrix defined

**URL:** <https://discourse.julialang.org/t/how-is-matrix-defined/60325>\
**Category:** Internals & Design\
**Created:** [April 30, 2021, 3:27pm UTC](https://discourse.julialang.org/t/how-is-matrix-defined/60325 "2021-04-30T15:27:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![feanor12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/feanor12/32/8212_2.png) [@feanor12](https://discourse.julialang.org/u/feanor12)\
**Post date:** [April 30, 2021, 3:27pm UTC](https://discourse.julialang.org/t/how-is-matrix-defined/60325/1 "2021-04-30T15:27:59Z")

</div>

I noticed that Matrix prints out that it is an alias. How would one define an alias for a custom type?

```julia
julia> Matrix{Int}
Matrix{Int64} (alias for Array{Int64, 2})

```

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [April 30, 2021, 3:30pm UTC](https://discourse.julialang.org/t/how-is-matrix-defined/60325/2 "2021-04-30T15:30:02Z")

</div>

Here’s a simple example:

```julia
julia> struct MyType{T, N}
       end

julia> const MyAlias{T} = MyType{T, 2}
MyAlias{T} where T (alias for MyType{T, 2} where T)

```

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [April 30, 2021, 3:30pm UTC](https://discourse.julialang.org/t/how-is-matrix-defined/60325/3 "2021-04-30T15:30:52Z")

</div>

You can see [here](https://github.com/JuliaLang/julia/blob/d7c6a9b4683635c426052d9db24019bc2bc366ef/base/array.jl#L71) how `Matrix` is defined in the Julia source code.

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [April 30, 2021, 3:49pm UTC](https://discourse.julialang.org/t/how-is-matrix-defined/60325/4 "2021-04-30T15:49:18Z")

</div>

Note that the `const` here is unnecessary. Type aliases like this will always be declared as constants.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [April 30, 2021, 3:55pm UTC](https://discourse.julialang.org/t/how-is-matrix-defined/60325/5 "2021-04-30T15:55:13Z")

</div>

PR to remove `const`s from /base/arrays.jl 😉 ?

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [April 30, 2021, 3:55pm UTC](https://discourse.julialang.org/t/how-is-matrix-defined/60325/6 "2021-04-30T15:55:59Z")

</div>

Way ahead of you 😉 : [NFC: remove unnecessary const before type aliases by simeonschaub · Pull Request #40671 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/40671)

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [April 30, 2021, 4:00pm UTC](https://discourse.julialang.org/t/how-is-matrix-defined/60325/7 "2021-04-30T16:00:11Z")

</div>

In which Julia version were these `const` declarations necessary?

---

<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:** [May 1, 2021, 12:18pm UTC](https://discourse.julialang.org/t/how-is-matrix-defined/60325/8 "2021-05-01T12:18:33Z")

</div>

> [@simeonschaub](#):
>
> Type aliases like this will always be declared as constants.

That’s just not true (on 1.6.1 at least). There is an observable difference between using `const` and not, and it’s what you’d expect:

```julia
julia> T = Int64
Int64

julia> T = Float64
Float64

```

vs

```julia
julia> const T = Int64
Int64

julia> T = Float64
ERROR: invalid redefinition of constant T
Stacktrace:
 [1] top-level scope
   @ REPL[2]:1

```

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [May 1, 2021, 12:56pm UTC](https://discourse.julialang.org/t/how-is-matrix-defined/60325/9 "2021-05-01T12:56:42Z")

</div>

I could probably have been a little more precise. What I meant was type aliases declared with `TypeVar`s on the left hand side, like `Foo{T} = Bar{T}`. That doesn’t hold true for regular assignment of course.
