Taken from "Scala with cats" (page 18):
Implicit Conversions
When you create a type class instance constructor using an implicit def, be sure to mark the parameters to the method as implicit parameters. Without this keyword, the compiler won’t be able to fill in the parameters during implicit resolution.implicit
methods with non‐implicit parameters form a different Scala pattern called an implicit conversion. This is also different from the previous section on Interface Syntax, because in that case theJsonWriter
is an implicit class with extension methods. Implicit conversion is an older programming pattern that is frowned upon in modern Scala code. Fortunately, the compiler will warn you when you do this. You have to manually enable implicit conversions by importingscala.language.implicitConversions
in your file
Can anyone please sum up well why implicit conversion are deprecated? What were there limit or issues? Why the approach with implicit parameters is better?
Note I know how to use the modern approach well, including chaining implicit and all. I am just curious as to what was the issue and why it was deprecated.
Monoid[List[Map[String, Option[Int]]]]
because I can derive theMonoid
ofList
because I can derive the one ofMap
because I can derive the one ofOption
because I know there is one forInt
- The latter, is just a way of saying I will turn anA
into aB
every time aB
is needed but the code produce anA
, in general, such pattern leads to code that is hard to read (understand), hard to maintain and can hide costly oeprations. – Luis Miguel Mejía Suárez