# Why would you create a subtype of \`Function\`?

**URL:** https://discourse.julialang.org/t/why-would-you-create-a-subtype-of-function/77087
**Category:** General Usage
**Created:** [February 25, 2022, 5:52pm UTC](https://discourse.julialang.org/t/why-would-you-create-a-subtype-of-function/77087 "2022-02-25T17:52:29Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![nchisholm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nchisholm/32/37414_2.png) [@nchisholm](https://discourse.julialang.org/u/nchisholm)
#### Post date: [February 25, 2022, 5:52pm UTC](https://discourse.julialang.org/t/why-would-you-create-a-subtype-of-function/77087/1 "2022-02-25T17:52:29Z")

</div>

I am curious about the utility of creating abstract or concrete subtypes of `Function`.

Aside from syntactic convenience, I am not sure of the distinction between a singleton type that is given several methods and a function definition.

```julia
struct MulPlus1T end
mulplus1 = MulPlus1T()
(::MulPlus1T)(x) = x+1
(::MulPlus1T)(x,y) = x*y+1

```

I can add as many methods as I want to `mulplus1`, so it seems to do everything a `Function` can.

Then, what utility is there to making `MyFuncType` a subtype of `<:Function`? As far as I know, it would allow `myfunc` to be used in methods of higher order functions that specifically demand that the argument `isa Function`, but I usually do not see this in practice because it would exclude user defined callable objects (which perhaps might be a subtype of some other abstract type and thus cannot be a `Function`).

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [February 25, 2022, 5:53pm UTC](https://discourse.julialang.org/t/why-would-you-create-a-subtype-of-function/77087/2 "2022-02-25T17:53:39Z")

</div>

there are probably two million things you can do with julia typing system that is useless.

`Function` is used for dispatching mostly, not to create subtype of directly:

```julia
julia> sin isa Function
true

```

---

<div class="post-metadata">

### Author: ![nchisholm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nchisholm/32/37414_2.png) [@nchisholm](https://discourse.julialang.org/u/nchisholm)
#### Post date: [February 25, 2022, 5:56pm UTC](https://discourse.julialang.org/t/why-would-you-create-a-subtype-of-function/77087/3 "2022-02-25T17:56:19Z")

</div>

Fair point, but then why have `Function` in the first place?

Is there a case where you would actually want to dispatch on `Function` and explicitly disallow user defined callable objects?

---

<div class="post-metadata">

### Author: ![favba](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/favba/32/2735_2.png) [@favba](https://discourse.julialang.org/u/favba)
#### Post date: [February 25, 2022, 9:58pm UTC](https://discourse.julialang.org/t/why-would-you-create-a-subtype-of-function/77087/4 "2022-02-25T21:58:03Z")

</div>

I think this is related to the good’old traits vs types discussion…  
If julia had traits you would dispatch on a `Is_callable` trait. Since julia is based on types you dispatch on the `Function` type…
