Skip to content
Playground(another site)

bynk.effect.bind_in_pure_context

Error An <- bind was used in a pure (non-effectful) context.

<- waits for an effect, so it is only allowed in a body that is itself effectful, one whose return type is Effect[T]. A function that returns a plain Int promises that it waits for nothing and reaches nothing outside, and a <- inside it would break that promise for every caller. A par block awaits too, and is refused in the same place. Change the return type to Effect[T] and return Effect.pure(…), or compute the value without an effect. Calling a function value that returns an Effect is bynk.effect.fn_value_in_pure_context.

Example

fn next(n: Int) -> Int {
let x <- Effect.pure(n) // ✗ `<-` in a function that returns a plain `Int`
x
}
fn next(n: Int) -> Effect[Int] { // ✓ effectful, so it may bind with `<-`
let x <- Effect.pure(n)
Effect.pure(x)
}

In the Book

See also

  • The grammar rule it governs: effect_let_stmt.
  • Every code in its category, Effects, on the diagnostic index.
  • bynk explain bynk.effect.bind_in_pure_context shows the same from the installed toolchain, without a network.