# Accessing type of a resulting expression at compile time?

**URL:** <https://discourse.julialang.org/t/accessing-type-of-a-resulting-expression-at-compile-time/5818>\
**Category:** General Usage\
**Created:** [September 11, 2017, 8:31am UTC](https://discourse.julialang.org/t/accessing-type-of-a-resulting-expression-at-compile-time/5818 "2017-09-11T08:31:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [September 11, 2017, 8:31am UTC](https://discourse.julialang.org/t/accessing-type-of-a-resulting-expression-at-compile-time/5818/1 "2017-09-11T08:31:58Z")

</div>

Hi,

I would like to access the type of an expression while writing macros?  
Is this doable?

Ex:

```nohighlight
@tss function fun(x::Int,y::Float64)
    if x > 4
         y+1
    else
         y-1
    end
end

 macro tss(func)
    #Here i want to calculate the type of y+1 to be Float64 
end

```

How can i do this?

Thanks

---

<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:** [September 11, 2017, 11:45am UTC](https://discourse.julialang.org/t/accessing-type-of-a-resulting-expression-at-compile-time/5818/2 "2017-09-11T11:45:14Z")

</div>

No, you can’t do that as far as I’m aware. For starters, because the type of any variable that appears in the method definition will in general depend on the types of the input arguments, which can’t be known at the time the macro does its work (imagine losing the `::Int` and `::Float64`).

---

<div class="post-metadata">

**Author:** ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Post date:** [September 11, 2017, 11:54am UTC](https://discourse.julialang.org/t/accessing-type-of-a-resulting-expression-at-compile-time/5818/3 "2017-09-11T11:54:15Z")

</div>

What would you like to do? [Generated functions](https://docs.julialang.org/en/stable/manual/metaprogramming/#Generated-functions-1) might solve your problem.
