Function name with Type constraining

Method dispatch does not treat function-like objects differently from typical functions. Say in the call foo(a, b), the dispatch is occurring over the types of the callable and the arguments (foo, a, b) isa Tuple{typeof(foo), typeof(a), typeof(b)}. In fact, you can add methods to foo with the same syntax (::typeof(foo))(c) = "blah", but typical functions are conveniently given a const name and extra behaviors via subtyping Function. If the struct type isn’t singleton (has no fields), then you can’t give any of its instances a const name, but otherwise you could opt into much of function’s behaviors.

1 Like