bynk.effect.fn_value_in_pure_context
Error An effectful function value was called in a pure context; like a capability call, it is legal only where the enclosing body is effectful.
Calling a function value whose type returns Effect[T] is an effect, just as calling a capability is, and effects are only allowed in a body that is itself effectful, one whose return type is an Effect. Bynk makes effects explicit so that a function's signature tells you whether it can touch the outside world: a function that returns a plain Int is pure and can be reasoned about as such. A call through a parameter would hide an effect behind that signature, so it is refused. Either make the function return Effect[T] and bind the call with <-, or take a pure function instead. A capability call from a handler that has not declared it is a different mistake, bynk.given.undeclared_capability.
Example
fn sneak(f: Int -> Effect[Int], x: Int) -> Int { let y = f(x) // ✗ an effect inside a pure function x}
fn sneak(f: Int -> Effect[Int], x: Int) -> Effect[Int] { // ✓ the function is effectful let y <- f(x) Effect.pure(y)}In the Book
See also
- The grammar rule it governs:
call. - Every code in its category, Effects, on the diagnostic index.
bynk explain bynk.effect.fn_value_in_pure_contextshows the same from the installed toolchain, without a network.