sealed trait F[A]
final case class FInt(a: Int) extends F[Boolean]
final case class FF[A](a: A) extends F[Either[Throwable, A]]
final case class FOption[A](o: Option[A]) extends F[Either[Throwable, A]]
def f[A](a: F[A]): A = a match {
case FInt(a) => a > 10
case FF(a) => Right(a).map(_ => "yyy") // why accept this?
case FOption(o) => o.fold[Either[Throwable, A]](Left(new Exception("")))(x => Right(x)) //why reject this?
}
I expect the compiler reject the "FF(a)" case but it accepted it.
I want the compiler accept the "FOption(o)" case but rejected by the compiler. :)
ideas? or I did something wrong?
Cheers,
Harry
sealed trait F[A]
final case class FInt(a: Int) extends F[Boolean] final case class FF[A](a: A) extends F[Either[Throwable, A]]
final case class FOption[A](o: Option[A]) extends F[Either[Throwable, A]]
def f[A](a: F[A]): A = a match {
case FInt(a) => a > 10
case ff: FF[a] => Right(ff.a).map(_ => "yyy") // now rejected - found : String("yyy") required: a
case fo: FOption[a] => fo.o.fold[Either[Throwable, a]](Left(new Exception("")))((x: a) => Right(x)) // now accepted
}
--
You received this message because you are subscribed to the Google Groups "Melbourne Scala User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-melb+...@googlegroups.com.
To post to this group, send email to scala...@googlegroups.com.
Visit this group at https://groups.google.com/group/scala-melb.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-melb+unsubscribe@googlegroups.com.
To post to this group, send email to scala...@googlegroups.com.
Visit this group at https://groups.google.com/group/scala-melb.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Melbourne Scala User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-melb+unsubscribe@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-melb+...@googlegroups.com.
To post to this group, send email to scala...@googlegroups.com.
Visit this group at https://groups.google.com/group/scala-melb.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Melbourne Scala User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-melb+...@googlegroups.com.
To post to this group, send email to scala...@googlegroups.com.
Visit this group at https://groups.google.com/group/scala-melb.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Melbourne Scala User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-melb+...@googlegroups.com.