# How is Number(1) allowed when Number is an abstract type?

**URL:** <https://discourse.julialang.org/t/how-is-number-1-allowed-when-number-is-an-abstract-type/26717>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [July 24, 2019, 5:08am UTC](https://discourse.julialang.org/t/how-is-number-1-allowed-when-number-is-an-abstract-type/26717 "2019-07-24T05:08:59Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sijun](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Sijun](https://discourse.julialang.org/u/Sijun)\
**Post date:** [July 24, 2019, 5:09am UTC](https://discourse.julialang.org/t/how-is-number-1-allowed-when-number-is-an-abstract-type/26717/1 "2019-07-24T05:09:00Z")

</div>

abstract type cannot be instantiated (no constructor). How are such expressions as Number(1), Number(1+im) possible then?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 24, 2019, 5:21am UTC](https://discourse.julialang.org/t/how-is-number-1-allowed-when-number-is-an-abstract-type/26717/2 "2019-07-24T05:21:51Z")

</div>

Try

```julia
@edit Number(1)

```

which takes you to the relevant method

```julia
(::Type{T})(x::T) where {T<:Number} = x

```

ie it is simply identity.

---

<div class="post-metadata">

**Author:** ![Sijun](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Sijun](https://discourse.julialang.org/u/Sijun)\
**Post date:** [July 24, 2019, 5:27am UTC](https://discourse.julialang.org/t/how-is-number-1-allowed-when-number-is-an-abstract-type/26717/3 "2019-07-24T05:27:15Z")

</div>

Ah, so it is simply an identity function with the same name. Thank you!

---

<div class="post-metadata">

**Author:** ![Sijun](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Sijun](https://discourse.julialang.org/u/Sijun)\
**Post date:** [July 24, 2019, 6:31am UTC](https://discourse.julialang.org/t/how-is-number-1-allowed-when-number-is-an-abstract-type/26717/4 "2019-07-24T06:31:36Z")

</div>

@Tamas_Papp, I have additional question:

I believe `(::Type{T})(x::T) where {T<:Number} = x` could have been written as `T(x::T) where T <: Number = x`, which looks simpler and in fact It works as I experimented. I wonder if there is any benefit to using the original syntax?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 24, 2019, 6:49am UTC](https://discourse.julialang.org/t/how-is-number-1-allowed-when-number-is-an-abstract-type/26717/5 "2019-07-24T06:49:26Z")

</div>

I think your experiments were misleading, the second option just defines a generic function `T` (with no methods).

---

<div class="post-metadata">

**Author:** ![tomaklutfu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomaklutfu/32/2411_2.png) [@tomaklutfu](https://discourse.julialang.org/u/tomaklutfu)\
**Post date:** [July 24, 2019, 6:55am UTC](https://discourse.julialang.org/t/how-is-number-1-allowed-when-number-is-an-abstract-type/26717/6 "2019-07-24T06:55:20Z")

</div>

How the latter should work as the former. `T` as method name and `T` as parameter are different things. It should not produce a constructor for `Number`. The former adds to an object `callability`(function like behaviour) but not necessarily a constructor, the latter is not(it produces a method named `T`).

---

<div class="post-metadata">

**Author:** ![Sijun](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Sijun](https://discourse.julialang.org/u/Sijun)\
**Post date:** [July 24, 2019, 7:23am UTC](https://discourse.julialang.org/t/how-is-number-1-allowed-when-number-is-an-abstract-type/26717/7 "2019-07-24T07:23:08Z")

</div>

I got your point. And you are right. Now I fully understood: As @Tamas_Papp said, it is misleading. The two statement are different things although they look like producing same effect. Thank you!

---

<div class="post-metadata">

**Author:** ![Sijun](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Sijun](https://discourse.julialang.org/u/Sijun)\
**Post date:** [July 24, 2019, 7:34am UTC](https://discourse.julialang.org/t/how-is-number-1-allowed-when-number-is-an-abstract-type/26717/8 "2019-07-24T07:34:22Z")

</div>

I think more accurately the latter produces a generic function T not method named T. 🙂

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 24, 2019, 7:36am UTC](https://discourse.julialang.org/t/how-is-number-1-allowed-when-number-is-an-abstract-type/26717/9 "2019-07-24T07:36:42Z")

</div>

> [@Sijun](#):
>
> The two statement are different things although they look like producing same effect.

The two forms have _very different effects_.

I assume that you tried it in the REPL, then tested for `Number(1)`, which kept working because the `T` function would not affect that at all. But this does not mean that nothing changed.

---

<div class="post-metadata">

**Author:** ![Sijun](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Sijun](https://discourse.julialang.org/u/Sijun)\
**Post date:** [July 24, 2019, 7:44am UTC](https://discourse.julialang.org/t/how-is-number-1-allowed-when-number-is-an-abstract-type/26717/11 "2019-07-24T07:44:40Z")

</div>

I could have missed that important point. I’ve learned a lot. Thank you 🙂
