Implicit keyword in LHS of for comprehension

Recently when I started to use for-comprehensions with monadic structures like Task a lot, I’ve noticed that this is not a valid Scala syntax

def app: Task[Unit] = 
  for {
    implicit foo <- createFoo
    implicit bar = createBarWithImplicitFoo
    _ <- runWithImplicitBar
  } yield ()

How hard would it be to make this valid Scala code?
Desugared version should look like this (and it compiles just fine)

createFoo.flatMap { implicit foo =>
  createBarWithImplicitFoo
}.flatMap { implicit bar =>
  runWithImplicitBar
}

https://github.com/scala/bug/issues/2823 (dates back to an era when the bug tracker was a mix of bugs and feature requests)

Oh, I see, there are so many issues linked I’ve lost a track. What blocks this feature from merging?

the story so far seems to end in the comments on https://github.com/scala/scala.github.com/pull/417

Actually, this is stuck because it requires a SIP and it’s missing a SIP champion. More details on https://github.com/scala/bug/issues/2823#issuecomment-295892603.

1 Like