# Pitch: Introduce (static) callables

**URL:** <https://forums.swift.org/t/pitch-introduce-static-callables/21732>\
**Category:** Pitches\
**Created:** [March 18, 2019, 3:15pm UTC](https://forums.swift.org/t/pitch-introduce-static-callables/21732 "2019-03-18T15:15:51Z")\
**Posts on this page:** 1\
**Showing post:** 58

<div class="post-metadata">

**Author:** ![dan-zheng](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dan-zheng/32/2534_2.png) [@dan-zheng](https://forums.swift.org/u/dan-zheng)\
**Post date:** [March 23, 2019, 10:48am UTC](https://forums.swift.org/t/pitch-introduce-static-callables/21732/58 "2019-03-23T10:48:54Z")

</div>

Update: the callable WIP branch is available at [Introduce callables. by dan-zheng · Pull Request #23517 · apple/swift · GitHub](https://github.com/apple/swift/pull/23517).  
The major change is the addition of the new `call` declaration kind, as described in this pitch.

Parsing is nearly done, sans an [unideal parsing diagnostic to fix](https://github.com/apple/swift/pull/23517/files#diff-4d4662adcc863c0adff0f039454ee53aR57).

- `call` is a keyword only in declaration-parsing contexts so `func call(...)` and `call(...)` apply expression are still valid.

- [Added parsing source compatibility tests](https://github.com/apple/swift/pull/23517/files#diff-48d69674bd65f258cccdc0ae6b6fcdf7), here's an excerpt:

[Type-checking needs a bit more work](https://github.com/apple/swift/pull/23517/files#r268389668) needs a bit more work, namely ["looking up all `call` declarations"](https://forums.swift.org/t/question-what-should-calldecl-inherit-from/21815/9) in a robust way. This means `call` declarations don't quite work as protocol requirements yet, but this will be fixed soon.

These examples work though:

```swift
struct SimpleCallable {
  call(_ x: Float) -> Float {
    return x
  }
}

let foo = SimpleCallable()
_ = foo(1)
_ = foo(foo(1))

// Test direct references.
_ = foo.call(1)
_ = [1, 2, 3].map(foo.call)
_ = foo.call(foo(1))
_ = foo(foo.call(1))
let _: (Float) -> Float = foo.call

// Generics work too.
struct Generic {
  call<T, U>(_ x: T, _ y: U) -> (T, U) {
    return (x, y)
  }
}
let generic = Generic()
_ = generic(1, 3.0)
_ = generic(generic, generic.call as ([Int], Float) -> ([Int], Float))

```

Feel free to take a look if you're interested - feedback appreciated!

---

_[View the full topic](https://forums.swift.org/t/pitch-introduce-static-callables/21732)._
