Skip to content
Playground(another site)

bynk.types.lambda_mismatch

Error A lambda's parameter count, parameter annotations, or body type do not match the expected function type.

A lambda is checked against the function type expected where it is written, such as the parameter it is passed for. It must take the same number of parameters, any annotation on a parameter must match that parameter's type, and its body must produce the result type, because the function it is passed to calls it with that shape and uses what comes back. Change the lambda to fit, or change the function type if that is what is wrong.

Example

fn apply(f: Int -> Int, x: Int) -> Int {
f(x)
}
fn total() -> Int {
apply((a, b) => a + b, 5) // ✗ `f` takes one argument
}
fn total() -> Int {
apply((a) => a + 1, 5) // ✓
}

In the Book

See also

  • The grammar rule it governs: lambda_expr.
  • Every code in its category, Type checking, on the diagnostic index.
  • bynk explain bynk.types.lambda_mismatch shows the same from the installed toolchain, without a network.