The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

548942 (2) [Avatar] Offline
#1
The explanation and the usage of Free Monad is super clear and clean. Few code snippets of chapter 5 doesnt compile, can you please help me with it. (or is it something wrong I'm doing not sure)

case class AccountRepoMutableInterpreter() extends AccountRepoInterpreter {
val table: MMap[String, Account] = MMap.empty[String, Account]

val step: AccountRepoF ~> Task = new (AccountRepoF ~> Task) {
override def apply[A](fa: AccountRepoF[A]): Task[A] = fa match {
case Query(no) =>
table.get(no).map { a => now(a) }
.getOrElse { fail(new RuntimeException(s"Account no $no not found")) }

case Store(account) => now(table += ((account.no, account))).void
case Delete(no) => now(table -= no).void
}
}

The compilation error says:
for case Query(no) "Expression of type Task[Account] doesn't confirm to expected type Task[A]"
for case Store(account) "Expression of type Task[Unit] doesn't confirm to expected type Task[A]"
for case Delete(no) "Expression of type Task[Unit] doesn't confirm to expected type Task[A]"
548942 (2) [Avatar] Offline
#2
I think It's the IDE (Intellij Idea) which is showing the error.
184390 (1) [Avatar] Offline
#3
I had the same issue and figured out that IntelliJ IDEA is fine with the code if you disable type-aware highlighting. You can disable this feature globally or selectively by surrounding the corresponding code with comment markers like this:

val step: AccountRepoF ~> Task = new (AccountRepoF ~> Task) {
  /*_*/
  def apply[A](fa: AccountRepoF[A]): Task[A] = fa match {
    case Query(no) =>
      table.get(no)
      .map(a => now(a))
      .getOrElse {
        fail(new RuntimeException(s"Account no '$no' not found"))
      }
    case Store(account) => now(table += (account.no -> account)).void
    case Delete(no) => now(table -= no).void
  }
  /*_*/
}


Unfortunately the documentation for type-aware highlighting isn't very detailed (see https://www.jetbrains.com/help/idea/2017.1/working-with-type-aware-highlighting.html) and I am really not sure if the behaviour in this case is a bug or a feature. I don't understand what's the point of being able to turn off highlighting for type-related errors in Scala code at all.