This happens because Scalaz does not define
Monad as being covariant in its first type argument (or, more precisely, type constructor argument). In other words, a
Monad[A] is considered a different type altogether from a
Monad[B], even if
A <: B. (More on covariance and contravariance)
There are good reasons why
Monad is invariant. One is: if you make the compiler believe that a
Monad[Id] is actually also valid as a
Monad[ExtendedId], you're bound to run into problems at some point — one of them is that wherever
pure is called, the compiler will infer an
ExtendedId result type, whereas only an
Id would be returned.
I think there isn't a technique to fix this cleanly — other than defining a
Monad[ExtendedId], or something like
implicit def idMonad[A[_] <: Id[_]]: Monad[A] = ...
which indeed is able to return a proper monad for all subclasses of
- Scala subtyping + implicit conversion problem
- Scala implicit conversion problem
- Is it possible in Intellij IDEA Scala plugin to know which implicit conversion was applied?
- Implicit conversion from String to Int in scala 2.8
- Scala implicit conversion from parent trait
- scala implicit or explicit conversion from iterator to iterable
- Implicit conversion from Int to Double in scala doesn't work
- Implicit conversion of java.util.List to scala List does not occur
- Scala 12.x and Java 11 `String.lines`, how to force the implicit conversion in a chained call?
- Implicit conversion classes for type-aliased Function types fail to compile in Scala
- Scala puts precedence on implicit conversion over "natural" operations... Why? Is this a bug? Or am I doing something wrong?
- Scala - implicit conversion with unapply
- scala source implicit conversion from Int to RichInt
- Difference between conversion with implicit function and implicit class in Scala
- Scala implicit type conversion and ==
- A problem of implicit conversions in scala 2.8
- incredible implicit Array conversion in scala
- Scala traits and implicit conversion confusion
- Scala implicit conversion is applying under some conditions but not others
- Scala implicit conversion on call-by-name parameter works differently depending on the function is overloaded or not
- Scala transitive implicit conversion
- Scala implicit conversion scope issues
- Scala - implicit conversion of Int to Numeric[Int]
- Scala implicit conversion not getting applied on Java argument pattern
- Scala Implicit Conversion Function Name Clashes
- Scala implicit conversion of primitive to AnyRef
- Implicit conversion between Scala collection types
- Scala and cats: Implicit conversion to identity monad
- Why won't Scala use implicit conversion here?
- scala abusive implicit conversion
More Query from same tag
- Link to library for Scala parser combinators in Eclipse
- Implementing IF condition in a map function spark scala
- Spark - split csv file using scala
- How can I pretty print a wrappedarray in Zeppelin/Spark/Scala?
- How to create an interface using scala
- Play 2.4 scala I am facing issues getting messages implicit in my code
- Scala ReactiveMongo example. Missed operations or implicits
- Scala: Covariant function
- Effectful update of Ref/MVar
- Why convert to a function
- Scala Multiline Anonymous Closure Mapping Over Array
- Chained Dataframe transformations in Scala with arguments and conditions
- How to use main class selection dialog?
- brunel not working on IBM data science experience
- Scala 3 + http4s problem with encode/decode json
- PlayFramework Scala dependency Injection Javax
- Is .g8 directory necessary?
- Play Framework Async Response Error
- Blocking Awaitable instances with Duration.Inf, best practice?
- Scala - how to define a structural type that refers to itself?
- Why the java version 8 which is selected in jenv is not in fact the current java on my Mac?
- return 1*1 pixel image in response play scala
- How do Scala collections use some variant types in contravariant position?
- Why there are two implementation of network io in scalaz-stream?
- Re-infer sequence type in Scala
- How i split the string with multiple delimeter in scala?
- How can I disable logging in console?
- In Scala, given a list of lists, how can I create one nested HashMap from the elements?
- sbt deprecation warning <<= replaced with := results in no main class found
- Gatling Generate OAuth2.0 token using callback URL not working