Skip to content

Differences in computation order IO.println() #4082

Closed Answered by mpilquist
AlekseyBulaev asked this question in Q&A
Discussion options

You must be logged in to vote

Take a look at the signature of IO.println:

def println[A](a: A)(implicit S: Show[A] = Show.fromToString[A]): IO[Unit] = ???

Note that a is not a by-name parameter so IO.println(anExpression) can be rewritten to the following without any change in evaluation order:

val tmp = anExpression
IO.println(tmp)

If the signature of println was def println[A](a: => A)(implicit S: Show[A] = Show.fromToString[A]): IO[Unit] instead, then we wouldn't be able to perform this val-extraction refactoring with changing the evaluation order, as the entire expression would be passed to println instead of first being evaluated.

Using this val-extraction rewrite in the definition tickingClock1 gives us:

val tic…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by AlekseyBulaev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants