0

Given the following trait (from this helpful shapeless talk):

scala> trait NatT[F[_], G[_]] { def apply[T](f: F[T]): G[T] } warning: there were two feature warnings; re-run with -feature for details defined trait NatT 

I believe this means that NatT accepts two higher-kinded parameters: F and G.

With this assumption, I tried to make an instance where F and G have type Option:

scala> case object Maybe extends NatT[Option, Option] { | override def apply(f: Option[Int]) = f | } <console>:8: error: object creation impossible, since method apply in trait NatT of type [T](f: Option[T])Option[T] is not de fined case object Maybe extends NatT[Option, Option] { ^ <console>:9: error: method apply overrides nothing. Note: the super classes of object Maybe contain the following, non final members named apply: def apply[T](f: Option[T]): Option[T] override def apply(f: Option[Int]) = f ^ 

How can I fix this attempt at making a Maybe instance?

1 Answer 1

6

Your apply method is missing the type parameter. Simple as that.

case object Maybe extends NatT[Option, Option] { def apply[A](f: Option[A]): Option[A] = f } 

Your attempts to define apply without a type parameter are seen as a different method, so it appears that apply is unimplemented. Given that F and G are supposed to be higher-kinds, it doesn't really make sense to try to fix them to Option[Int].

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.