Skip to content
Playground(another site)

bynk.effect.do_in_pure_context

Error A do statement was used in a pure (non-effectful) context.

do e runs an effect as a statement, so like <- it belongs in a body that is itself effectful, one whose return type is Effect[T]. A function that returns a plain Int promises to wait for nothing and reach nothing outside, and a do inside it would break that promise for every caller. Change the return type to Effect[T] and end with Effect.pure(…), or drop the do. The same mistake with <- is bynk.effect.bind_in_pure_context.

Example

fn ping() -> Effect[()] {
Effect.pure(())
}
fn run() -> Int {
do ping() // ✗ `do` in a function that returns a plain `Int`
5
}
fn run() -> Effect[Int] { // ✓ effectful, so `do` is allowed
do ping()
Effect.pure(5)
}

In the Book

See also

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