# How to type annotate functions which take functions as args

**URL:** https://discourse.julialang.org/t/how-to-type-annotate-functions-which-take-functions-as-args/14158
**Category:** New to Julia
**Created:** [August 27, 2018, 10:25pm UTC](https://discourse.julialang.org/t/how-to-type-annotate-functions-which-take-functions-as-args/14158 "2018-08-27T22:25:14Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![dawbarton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dawbarton/32/215461_2.png) [@dawbarton](https://discourse.julialang.org/u/dawbarton)
#### Post date: [August 27, 2018, 11:04pm UTC](https://discourse.julialang.org/t/how-to-type-annotate-functions-which-take-functions-as-args/14158/3 "2018-08-27T23:04:41Z")

</div>

Alternatively if you just want your function `h` to call any function passed, not just `f` (which is presumably the case since otherwise you wouldn’t have it as an argument and just fixed in the code) you can use the `::Function` annotation. (I don’t know Haskell so I can’t tell if that’s what you are trying to do.) For example,

```julia
julia> function h(_f::Function, x::Number)
           return g(_f(x))
       end
h (generic function with 1 method)

julia> supertype(typeof(f))
Function

julia> f isa Function
true

julia> g isa Function
true

```

That said, it’s often useful not to restrict functions to subtypes of `Function` since there are other ways of creating objects that you can call. For example, you can have a callable struct.

```julia
struct MyStruct
    a::Float64
end

function (mystruct::MyStruct)(b::Number)
    mystruct.a + b
end

julia> astruct = MyStruct(1.2)
MyStruct(1.2)

julia> astruct(3)
4.2

julia> astruct isa Function
false

```

As such, I tend to leave off function annotations and just try calling whatever is passed. (Cf. [duck typing](https://en.wikipedia.org/wiki/Duck_typing).)

---

_[View the full topic](https://discourse.julialang.org/t/how-to-type-annotate-functions-which-take-functions-as-args/14158)._
