Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get function from function type?

Suppose I have hold of the concrete type of a normal, named Julia function, F = typeof(f). Is it possible to get back f from F? I assume this should work in principle, since F is a singleton type.

like image 918
phipsgabler Avatar asked Feb 17 '26 19:02

phipsgabler


2 Answers

You can go with Core.Compiler.singleton_type function which returns the instance field for a concrete DataType. I think this function is used for the same objective as yours (not only for this objective) in Core.Compiler during compilation. This is probably considered "more internal" than directly accessing instance field.

julia> Core.Compiler.singleton_type(typeof(sum))
sum (generic function with 13 methods)
like image 136
hckr Avatar answered Feb 19 '26 10:02

hckr


I would use F.instance, but maybe there is some better solution (as this one is using the internals).

like image 40
Bogumił Kamiński Avatar answered Feb 19 '26 12:02

Bogumił Kamiński



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!