Bonus answer:
There are a lot of questions about type erasure, take a look at How do I get around type erasure on Scala? Or, why can't I get the type parameter of my collections? You can write something like
case FlatMap(y: IO[A], g: gType@unchecked) if g.isInstanceOf[gType] =>