Skip to content

Instantly share code, notes, and snippets.

@maxaf
Created December 26, 2011 08:13
Show Gist options
  • Save maxaf/1520748 to your computer and use it in GitHub Desktop.
Save maxaf/1520748 to your computer and use it in GitHub Desktop.
Strange/unexpected unsafePerformIO behavior
import scalaz._
import Scalaz._
import scalaz.effects._
val a = println("a here").pure[IO]
val b = println("b here").pure[IO]
val c = a.flatMap(_ => b.flatMap(_ => println("c here").pure[IO]))
c.unsafePerformIO // prints 3 lines as expected
c.unsafePerformIO // expect 0 lines to be printed, but...
c.unsafePerformIO // and again...
c.unsafePerformIO // again...
c.unsafePerformIO // ad infinitum
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import scalaz._
import scalaz._
scala> import Scalaz._
import Scalaz._
scala> import scalaz.effects._
import scalaz.effects._
scala> val a = println("a here").pure[IO]
a: scalaz.effects.IO[Unit] = scalaz.effects.IO$$anon$2@26c46c5a
scala> val b = println("b here").pure[IO]
b: scalaz.effects.IO[Unit] = scalaz.effects.IO$$anon$2@1f46e809
scala> val c = a.flatMap(_ => b.flatMap(_ => println("c here").pure[IO]))
c: scalaz.effects.IO[Unit] = scalaz.effects.IO$$anon$2@46249be9
scala> c.unsafePerformIO // prints 3 lines as expected
a here
b here
c here
scala> c.unsafePerformIO // expect 0 lines to be printed, but...
c here
scala> c.unsafePerformIO // and again...
c here
scala> c.unsafePerformIO // again...
c here
scala> c.unsafePerformIO // ad infinitum
c here
scala>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment