# Wrap and inherit Number

**URL:** <https://discourse.julialang.org/t/wrap-and-inherit-number/4799>\
**Category:** General Usage\
**Tags:** question\
**Created:** [July 12, 2017, 11:24am UTC](https://discourse.julialang.org/t/wrap-and-inherit-number/4799 "2017-07-12T11:24:34Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [July 13, 2017, 9:00am UTC](https://discourse.julialang.org/t/wrap-and-inherit-number/4799/21 "2017-07-13T09:00:00Z")

</div>

Very cool.

I’d like to add some clarity as well:  
The “thing” that would be most useful (and maybe I should open a new topic for this), is if we could just have something that acts exactly like a `Number` (in every meaning), but that we can override some of the functions that already accept it as an argument.

So here’s an instance of `Float64`:  
`Float64(33.0)`  
We can do all sorts of things with it. Here is an instance of a custom type `A`:  
`A(33.0)`  
We can do exactly the same things like the `Float64` version from before. Now I change the existing `sin` function to the following (silly):  
`sin(x::A) = 2x`.  
There. Instances of `A` do everything, say, floats can do, and I modified the behavior of a few select functions. Winning.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [July 13, 2017, 3:53pm UTC](https://discourse.julialang.org/t/wrap-and-inherit-number/4799/22 "2017-07-13T15:53:28Z")

</div>

How would you address [https://github.com/JuliaLang/julia/issues/9821#issuecomment-70381499](https://github.com/JuliaLang/julia/issues/9821#issuecomment-70381499)?

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [July 21, 2017, 2:43pm UTC](https://discourse.julialang.org/t/wrap-and-inherit-number/4799/23 "2017-07-21T14:43:28Z")

</div>

I liked the idea of `TypedDelegation.jl` very much, will these macros be in Base by any chance at some point?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [July 21, 2017, 3:44pm UTC](https://discourse.julialang.org/t/wrap-and-inherit-number/4799/24 "2017-07-21T15:44:07Z")

</div>

> [@juliohm](#):
>
> will these macros be in Base by any chance at some point?

Almost certainly not, since they are unlikely to be needed for anything in Base.

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [July 21, 2017, 3:46pm UTC](https://discourse.julialang.org/t/wrap-and-inherit-number/4799/25 "2017-07-21T15:46:12Z")

</div>

Thank you @stevengj, good to know.

---

<div class="post-metadata">

**Author:** ![rfourquet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rfourquet/32/3610_2.png) [@rfourquet](https://discourse.julialang.org/u/rfourquet)\
**Post date:** [July 21, 2017, 4:31pm UTC](https://discourse.julialang.org/t/wrap-and-inherit-number/4799/26 "2017-07-21T16:31:17Z")

</div>

> [@stevengj](#):
>
> Almost certainly not, since they are unlikely to be needed for anything in Base.

It’s not totally true, see e.g `length`, `size` etc. for `Generator` in generator.jl. Some time ago I started a branch with this delegate functionality, but thought I indeed needed to find more cases to push that into Base! In my case, I needed indirection for the iteration protocol (similar to the `iter` function in python).

---

<div class="post-metadata">

**Author:** ![liuyxpp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/liuyxpp/32/9870_2.png) [@liuyxpp](https://discourse.julialang.org/u/liuyxpp)\
**Post date:** [March 23, 2023, 5:14am UTC](https://discourse.julialang.org/t/wrap-and-inherit-number/4799/27 "2023-03-23T05:14:32Z")

</div>

Sorry for bumping this rather old post. But, any updates on this direction? I try to define a set of structs representing different kinds of prices (e.g. `OpenPrice`, `ClosePrice`, etc.), which shall behave like a Float but use its type name to do multiple dispatch.

[Previous page](https://discourse.julialang.org/t/wrap-and-inherit-number/4799.md?page=1)
