1

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 pa­rameters. 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 the JsonWriter is an implicit class with extension methods. Implicit con­version is an older programming pattern that is frowned upon in mod­ern Scala code. Fortunately, the compiler will warn you when you do this. You have to manually enable implicit conversions by importing scala.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.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
MaatDeamon
  • 9,532
  • 9
  • 60
  • 127
  • 2
    **Implicit derivation** is very different from **implicit conversions** the former is a logic proof when you can say something like I can derive the `Monoid[List[Map[String, Option[Int]]]]` because I can derive the `Monoid` of `List` because I can derive the one of `Map` because I can derive the one of `Option` because I know there is one for `Int` - The latter, is just a way of saying I will turn an `A` into a `B` every time a `B` is needed but the code produce an `A`, 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 Dec 05 '20 at 15:39
  • 3
    However, there are indeed _"valid use cases"_. But, IMHO, those a little and should be reserved when there is no other cleaner solution. For an in-depth discussion about the topic read: https://contributors.scala-lang.org/t/can-we-wean-scala-off-implicit-conversions/4388 – Luis Miguel Mejía Suárez Dec 05 '20 at 15:40
  • 2
    Implicit conversions are not **deprecated** https://docs.scala-lang.org/tour/implicit-conversions.html http://dotty.epfl.ch/docs/reference/contextual/conversions.html – Dmytro Mitin Dec 05 '20 at 16:59
  • 3
    There are many difficulties with type inference in presence of implicit conversions https://stackoverflow.com/questions/63964610/implicit-view-not-working-is-my-implicit-def-to-blame https://stackoverflow.com/questions/62630439/in-scala-are-there-any-condition-where-implicit-view-wont-be-able-to-propagate https://stackoverflow.com/questions/62205940/when-calling-a-scala-function-with-compile-time-macro-how-to-failover-smoothly https://stackoverflow.com/questions/62751493/scala-kleisli-throws-an-error-in-intellij ... – Dmytro Mitin Dec 05 '20 at 17:11
  • 3
    ... https://stackoverflow.com/questions/63002466/what-are-the-hidden-rules-regarding-the-type-inference-in-resolution-of-implicit https://stackoverflow.com/questions/63697952/scala-ambigious-implicit-values-but-the-right-value-is-not-event-found/ – Dmytro Mitin Dec 05 '20 at 17:11
  • Please put answers in answers, not comments. – Tim Dec 06 '20 at 10:46

1 Answers1

2

Martin Odersky, the inventor of Scala, has indicated that implicits (and implicit conversions) are being deprecated in scala 3.1 and will eventually be removed from the language altogether.

the implicit functionality will be replaced with Extension Methods and Givens. Extension Methods and Givens provide a more tighter functional solution that doesn't introduce the unsuspecting and hidden side effects that implicits cause. Odersky now views implicits as a “recipe for disaster" and are "too implicit" which was his motivation to replace their functionality in 3.x.

https://www.slideshare.net/Lightbend/scala-3-is-coming-martin-odersky-shares-what-to-know

https://hub.packtpub.com/is-scala-3-0-a-new-language-all-together-martin-odersky-its-designer-says-yes-and-no/

Andrew Norman
  • 843
  • 9
  • 22
  • 1
    Since then I found out why! I will post the specific answer. But there is a thread in google where they emphasize moving away from implicit conversion to context bound and the reason for this is clear ! None the less thanks for the links – MaatDeamon Feb 05 '21 at 20:47