Accessing type of a resulting expression at compile time?

Hi,

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

Ex:

@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

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).

What would you like to do? Generated functions might solve your problem.

1 Like