# Is there a way to get f from typeof(f)?

**URL:** https://discourse.julialang.org/t/is-there-a-way-to-get-f-from-typeof-f/18818
**Category:** General Usage
**Created:** [December 19, 2018, 4:35am UTC](https://discourse.julialang.org/t/is-there-a-way-to-get-f-from-typeof-f/18818 "2018-12-19T04:35:04Z")
**Posts on this page:** 1
**Showing post:** 12

<div class="post-metadata">

### Author: ![jameson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jameson/32/23_2.png) [@jameson](https://discourse.julialang.org/u/jameson)
#### Post date: [December 28, 2018, 5:16pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-get-f-from-typeof-f/18818/12 "2018-12-28T17:16:33Z")

</div>

> [@Tamas\_Papp](#):
>
> Perhaps `Base.instances` could provide an instance of all singleton types, including functions.

Note that for anyone reading through this statement is false. Functions are not always singleton types, and are thus should not be assumed to be a subset of “all singleton types”. In fact, all objects are can be used as function arguments, so Any object may be given there.

Most of the “solutions” presented here are wrong: you should never need to access “.instance”. This is an internal API and not stable. The correct way to do this is to store the actual function object itself, and always refer to it by value and don’t try to do this in the type-domain. Adopting the original example, we get the much-shortened:

```julia
julia> struct MyStruct{F}
           f::F
       end

julia> ExtractFun(s::MyStruct) = s.f

```

---

_[View the full topic](https://discourse.julialang.org/t/is-there-a-way-to-get-f-from-typeof-f/18818)._
