# Specify type of function

**URL:** <https://discourse.julialang.org/t/specify-type-of-function/18373>\
**Category:** General Usage\
**Created:** [December 6, 2018, 12:39pm UTC](https://discourse.julialang.org/t/specify-type-of-function/18373 "2018-12-06T12:39:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![linuslagerhjelm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/linuslagerhjelm/32/1771_2.png) [@linuslagerhjelm](https://discourse.julialang.org/u/linuslagerhjelm)\
**Post date:** [December 6, 2018, 12:39pm UTC](https://discourse.julialang.org/t/specify-type-of-function/18373/1 "2018-12-06T12:39:12Z")

</div>

Let’s say that I want to write a higher order function (a function that accepts another function) I know I can accept it like:

```julia
fun(f::Function, args...) = ...

```

What I want to know if it is possible to be more specific about the type of f, if I expect the function to have a certain format, for example a predicate function would need to accept two values of a special type and return a Bool. Something like:

```julia
fun(f::(x1::T, x2::T)::Bool, Vector{T}) where T = ...

```

If this is not currently possible I think it would be a nice feature request.

---

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [December 6, 2018, 12:47pm UTC](https://discourse.julialang.org/t/specify-type-of-function/18373/2 "2018-12-06T12:47:47Z")

</div>

You can check this comment and the rest of the thread:

> [@Enforcing function signatures by both argument & return types](https://discourse.julialang.org/t/enforcing-function-signatures-by-both-argument-return-types/8174/13):
>
> It’s becoming a bit complicated but I think [this](https://gist.github.com/jonathanBieler/41da202b1d3e914e803cd79c83ac3ed9) works: Now you can provide the signature you want to the constructor and it look through the function’s methods to find a match (returns an error otherwise) f(z,x::Int,y::Int) = x+z f(x::Int,y::Float64) = x+y f(x::Int) = x f() = 2 julia\> tf1 = TypedFunction(f, (Int,Float64),(Float64)) f: Tuple{Int64,Float64} → Float64 You can use dispatch to put constrains on input/output types: g(f::TypedFunction{T,I,O}) where {T,I\<:Tuple{Number,Float64},O\<:…

---

<div class="post-metadata">

**Author:** ![linuslagerhjelm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/linuslagerhjelm/32/1771_2.png) [@linuslagerhjelm](https://discourse.julialang.org/u/linuslagerhjelm)\
**Post date:** [December 6, 2018, 12:54pm UTC](https://discourse.julialang.org/t/specify-type-of-function/18373/3 "2018-12-06T12:54:57Z")

</div>

Ah nice! Thank you! 😃
