# Function builder cannot infer generic parameters even though direct call to \`buildBlock\` can

**URL:** <https://forums.swift.org/t/function-builder-cannot-infer-generic-parameters-even-though-direct-call-to-buildblock-can/35886>\
**Category:** Using Swift\
**Tags:** question, function-builder\
**Created:** [April 27, 2020, 1:56am UTC](https://forums.swift.org/t/function-builder-cannot-infer-generic-parameters-even-though-direct-call-to-buildblock-can/35886 "2020-04-27T01:56:08Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![John\_McCall](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/john_mccall/32/1351_2.png) [@John\_McCall](https://forums.swift.org/u/John_McCall)\
**Post date:** [April 27, 2020, 6:59pm UTC](https://forums.swift.org/t/function-builder-cannot-infer-generic-parameters-even-though-direct-call-to-buildblock-can/35886/14 "2020-04-27T18:59:03Z")

</div>

You wouldn't have to add explicit type annotations within the body; that would clearly not be consistent with current type-checker behavior.

A one-way constraint is like the status quo for type-checking a variable binding:

```swift
let x = 15
return x + UInt(27)

```

This doesn't type-check because type information only flows "one way" through the variable binding: we decide that `x: Int` without considering that `x` is required to be convertible to `UInt` on the next line.

Another way of understanding the use of one-way constraints in function builders is that they're as if the closure was transformed to assign all the statement results into locals. So given this closure:

```swift
Sequential { 
  Conv2D<Float>(...)
  AvgPool2D<Float>(...)
  Flatten<Float>()
  Dense<Float>(...)
  Dense<Float>(...)
}

```

Instead of thinking of the transform like this:

```swift
Sequential {
  LayerBuilder.buildBlock(
    Conv2D<Float>(...),
    AvgPool2D<Float>(...),
    Flatten<Float>(),
    Dense<Float>(...),
    Dense<Float>(...))
}

```

Think of it more like this:

```swift
Sequential { 
  let a = Conv2D<Float>(...)
  let b = AvgPool2D<Float>(...)
  let c = Flatten<Float>()
  let d = Dense<Float>(...)
  let e = Dense<Float>(...)
  return LayerBuilder.buildBlock(a, b, c, d, e)
}

```

---

_[View the full topic](https://forums.swift.org/t/function-builder-cannot-infer-generic-parameters-even-though-direct-call-to-buildblock-can/35886)._
