<@U0QKQ7H3R> Both `println` and `readLine` perform...
# arrow
r
@nfrankel Both
println
and
readLine
perform effects.
println
causes the external effect that when applied something gets printed to a log or system.out.
readLine
causes the effect that regardless of the input parameters you get always something different back therefore introduces the same kind of effect you would have if you had a random number generator in your computation. They both make functions impure since you can’t expect the function to produce the same output for a given input without either modifying the external world or making it non deterministic. For that reason effects are encapsulated with either
IO
or if you are using type classes anything above
MonadDefer
. Proof that these effects happen is:
Copy code
fun Applicative<F>.printOpImpure: Kind<F, Unit> = pure(println("whatever")) // because pure is stric println gets evaluated each time `printOpImpure` is invoked and can't be part of the final IO loop that controls effects and exceptions.
fun MonadDefer<F>.printOpPure: Kind<F, Unit> =  invoke { println("whatever") } // because `invoke` in MonadDefer is lazy invoking `printOpPure` will not cause printing to happen and the effect will be treated along the rest of computation when executing the `program.unsafeRunSync` at the edge