Description
EDIT Better written post about why the current (at the time of this writing, Oct 9, 2016) type class encoding is insufficient: http://typelevel.org/blog/2016/09/30/subtype-typeclasses.html )
One issue with the current approach is if you want to do MTL style programming, you end up having duplication. A short, contrived, example:
trait MonadMagic[F[_]] extends Monad[F] {
def magic: F[Int]
}
Now I want to define MonadMagic[Option]
.. but that means I also need to re-implement the Monad
flatMap
and pure
methods, which leads to duplication and makes me uncomfortable.
I suppose it could be solved by putting the Monad[Option]
definition in a trait
and exposing it for people to mix-in.. but then we'd have to do it for every data type. Which maybe isn't a big deal? But perhaps a deficiency of the current approach.
I suppose you could also do something like
trait MonadMagic[F[_]] {
def monad: Monad[F]
}
and provide an implicit conversion [F]MonadMagic[F] => Monad[F]
but that departs from how we are currently encoding things.
I find some solution to this is important so as to not hinder MTL style programming which I find is an elegant way to encode EDSLs like Free
modulo the need to explicitly reify the AST and thus presumably more performant.