# Why is Julia not inferring the output type of f(x,y)=x+y?

**URL:** <https://discourse.julialang.org/t/why-is-julia-not-inferring-the-output-type-of-f-x-y-x-y/73634>\
**Category:** Performance\
**Tags:** inference, code\_warntype\
**Created:** [December 26, 2021, 3:34am UTC](https://discourse.julialang.org/t/why-is-julia-not-inferring-the-output-type-of-f-x-y-x-y/73634 "2021-12-26T03:34:05Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![c42f](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/c42f/32/52842_2.png) [@c42f](https://discourse.julialang.org/u/c42f)\
**Post date:** [December 26, 2021, 3:53am UTC](https://discourse.julialang.org/t/why-is-julia-not-inferring-the-output-type-of-f-x-y-x-y/73634/3 "2021-12-26T03:53:01Z")

</div>

Julia’s type inference algorithm needs to keep compilation time “reasonably small” while also computing precise type information where it “seems likely” that this would result in fast code at runtime.

Fast code machine code can generally be produced when type inference can compute concrete types (or small `Union`s of concrete types). But when an abstract type like `Number` is encountered with many subtypes, it’s unlikely to be better to infer `Number` than to widen the type to `Any`. So type inference has just chosen to widen the type here, computing a less precise result in favor of lowering compilation time.

By the way, here’s the subtypes of `Number` defined in Base. There’s also many others in external libraries:

```julia
Number
├─ Complex
└─ Real
   ├─ AbstractFloat
   │ ├─ BigFloat
   │ ├─ Float16
   │ ├─ Float32
   │ └─ Float64
   ├─ AbstractIrrational
   │ └─ Irrational
   ├─ Integer
   │ ├─ Bool
   │ ├─ Signed
   │ │ ├─ BigInt
   │ │ ├─ Int128
   │ │ ├─ Int16
   │ │ ├─ Int32
   │ │ ├─ Int64
   │ │ └─ Int8
   │ └─ Unsigned
   │ ├─ UInt128
   │ ├─ UInt16
   │ ├─ UInt32
   │ ├─ UInt64
   │ └─ UInt8
   └─ Rational

```

> [@vedantroy](#):
>
> Is it bad if your code has types like `Number` (instead of more concrete types like `Float64` )?

In short, yes.

---

_[View the full topic](https://discourse.julialang.org/t/why-is-julia-not-inferring-the-output-type-of-f-x-y-x-y/73634)._
