# How do I type lambda functions?

**URL:** <https://discourse.julialang.org/t/how-do-i-type-lambda-functions/44461>\
**Category:** General Usage\
**Created:** [August 6, 2020, 10:42pm UTC](https://discourse.julialang.org/t/how-do-i-type-lambda-functions/44461 "2020-08-06T22:42:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![NightMachinary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nightmachinary/32/14196_2.png) [@NightMachinary](https://discourse.julialang.org/u/NightMachinary)\
**Post date:** [August 6, 2020, 10:42pm UTC](https://discourse.julialang.org/t/how-do-i-type-lambda-functions/44461/1 "2020-08-06T22:42:19Z")

</div>

I want to do something like this:

```julia
struct Foo
  myFunc::Function{Int,Float64} # invalid Julia
end
zee(a::Int, b::Float64) = a+b
bar = Foo(zee)

```

---

<div class="post-metadata">

**Author:** ![anon37204545](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon37204545](https://discourse.julialang.org/u/anon37204545)\
**Post date:** [August 6, 2020, 10:55pm UTC](https://discourse.julialang.org/t/how-do-i-type-lambda-functions/44461/2 "2020-08-06T22:55:05Z")

</div>

This works:

```julia
struct Foo
  myFunc::Function
end
zee(a::Int, b::Float64) = a+b
bar = Foo(zee)

```

but I’m not sure that’s the best way to achieve your goal in Julia. What do you want to use this code for?

---

<div class="post-metadata">

**Author:** ![NightMachinary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nightmachinary/32/14196_2.png) [@NightMachinary](https://discourse.julialang.org/u/NightMachinary)\
**Post date:** [August 6, 2020, 11:10pm UTC](https://discourse.julialang.org/t/how-do-i-type-lambda-functions/44461/3 "2020-08-06T23:10:40Z")

</div>

For organization purposes. It helps to clarify the interface design.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 7, 2020, 12:11pm UTC](https://discourse.julialang.org/t/how-do-i-type-lambda-functions/44461/4 "2020-08-07T12:11:27Z")

</div>

Julia’s type system doesn’t have what is common known as “arrow types” in other languages (eg Haskell), so you can’t do this.

Also, note that it may not even make sense conceptually, since adding a new _method_ would just extend the “type” of a function, even if it would not necessarily make Julia recompile code for existing call paths.

That said, functions have a type, which is really a singleton. You can obtain it with `typeof`. For the example above, use something like

```julia
struct Foo{T}
    f:T
end

```

Note that I didn’t subtype to `<:Function`, callables can behave as functions.

---

<div class="post-metadata">

**Author:** ![NightMachinary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nightmachinary/32/14196_2.png) [@NightMachinary](https://discourse.julialang.org/u/NightMachinary)\
**Post date:** [August 7, 2020, 12:29pm UTC](https://discourse.julialang.org/t/how-do-i-type-lambda-functions/44461/5 "2020-08-07T12:29:44Z")

</div>

Does this parametrization have a performance benefit?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 7, 2020, 12:40pm UTC](https://discourse.julialang.org/t/how-do-i-type-lambda-functions/44461/6 "2020-08-07T12:40:02Z")

</div>

[https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-abstract-container-1](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-abstract-container-1)
