Questions tagged [implicit]

An implicit in Scala is a function applied or a parameter provided without explicitly appearing in the source code.

implicit
322 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
53 votes
0 answers
1k views

Materialize the Value for a Type that has One Inhabitant

Thanks to @MilesSabin's answer I can write a type level Fibonacci sequence: sealed trait Digit case object Zero extends Digit case object One extends Digit sealed trait Dense { type N <: Dense } ...
beefyhalo's user avatar
  • 1,741
7 votes
0 answers
187 views

Generic method overloading via implicit class

When I try to create an extension for the class via implicit class and overload existing generic method, it fails with compilation error: error: overloaded method value getAs with alternatives: (...
Artavazd Balayan's user avatar
6 votes
0 answers
157 views

Implicit conversion is not applied if a method has type parameter

The question is based on the discussion here. This is the setup: implicit def CToC2(obj: C1): C2 = { new C2() } class C1() { def f[U](f: (Int, Int) => U): U = f(1, 1) } class C2() { def f[...
jamborta's user avatar
  • 5,170
6 votes
0 answers
398 views

diverging implicit expansion

Can someone please explain to me why I get a 'diverging implicit expansion error' here? I think it has to do with the type synonym type MyIdType = String but I am not sure why. import org.scalacheck....
dmz73's user avatar
  • 1,608
6 votes
0 answers
489 views

Ambiguity in Low priority implicits

I have the following snippet of Scala code: import java.io.PrintWriter trait Write[-A] { def apply(out: PrintWriter)(x: A): Unit } trait LowPriorityWrites { implicit object any ...
pathikrit's user avatar
  • 33.1k
5 votes
0 answers
688 views

How to pass data model via implicit deeplink, between fragments

I need to pass a data model from one fragment to another via implicit deeplink, but I didn't find a way how to do it. I only found smth like this: val request = NavDeepLinkRequest.Builder .fromUri(...
Terry's user avatar
  • 63
5 votes
0 answers
107 views

Type Class: Not using `asInstanceOf`, but still getting `ClassCastException`

Consider the following relatively simple code: import scala.deriving.Mirror trait TC[A]: def show: A object TC: inline def derived[A](using m: Mirror.ProductOf[A]): TC[A] = new TC[A]: ...
Koosha's user avatar
  • 1,554
5 votes
0 answers
355 views

Why is Try the default implicit Applicative instance in cats

Playing around with cats, I have noticed a certain behavior which I cannot quite explain: import cats.implicits._ ... def wrapA[A, F[_]](v: A)(implicit F: Applicative[F]): F[A] = F.pure(v) not a ...
kostja's user avatar
  • 61k
5 votes
0 answers
210 views

How can I chain generic implicits in Scala?

There is this post that discusses chaining of implicits but I think it doesn't cover my case because I have generic implicits. Sample project that demonstrates the issue is located here. To reproduce ...
expert's user avatar
  • 29.7k
5 votes
1 answer
158 views

Finding implicit values in the companion object of a nested type

I have a trait Outer with a member F that is a type constructor. I want to supply type-class instances for F, but somehow at one point the implicit resolution of scalac stops working. I tried to ...
ziggystar's user avatar
  • 28.5k
5 votes
0 answers
538 views

Scala implicit class to Java static method for interop?

Is it possible to automatically generate companion Java static methods for interop from an implicit class definition ? e.g.: class Foo() object FooOps { implicit class FooOps(foo: Foo) extends ...
Edoardo Vacchi's user avatar
4 votes
0 answers
142 views

What causes AbstractMethodError for scala implicit val?

I have a gears library, depending on "org.typelevel" %% "cats-core" % "2.7.0", "org.typelevel" %% "cats-effect" %...
amorfis's user avatar
  • 15.6k
4 votes
0 answers
145 views

Where should I put typeclass instances?

Lets say I develop a new public data structure, lets call it FancyList. It has no external dependencies and everybody loves it. This FancyList turns out to be a Functor, Monad, MonoidK, and Traverse. ...
cmhteixeira's user avatar
4 votes
0 answers
240 views

Scala how to create implicit object with same name as function

Given the following trait and companion object definitions: trait Api { def foo(s: String): String } object Api extends Api { override def foo(s: String) = s } I would like to extend the ...
smac89's user avatar
  • 41.4k
4 votes
0 answers
280 views

how would one define a scala implicit in a java library?

As a bit of background, I'm using joda DateTime from Scala. It seems that everywhere a Scala developer uses Joda DateTime, they define some implicit datetimeOrdering, which they then import. Each ...
nairbv's user avatar
  • 4,224
4 votes
1 answer
1k views

Custom Implicit Intent in Android not working

I am testing implicit intent. I have two Small Test Applications: 1st AndroidManifest.xml: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/...
Sudipta Deb's user avatar
4 votes
0 answers
535 views

cloth sim with implicit integration unstable problem

Im implementing a gpu based cloth simulation using mass-spring model with a backward euler integration. The linear system is solved by using the conjugate gradient solver with filter. Everything is ...
physimrookie's user avatar
3 votes
0 answers
43 views

Can I introduce an implicit precedence relation between packages as with objects?

I was wondering how to place effectively the same implicit conversion in more than one package in such a way that importing the contents of one is enough, but importing all doesn't introduce conflicts....
Turin's user avatar
  • 2,210
3 votes
0 answers
137 views

What are the hidden rules regarding the type inference in resolution of implicit conversions?

I thought that if the following compiles: implicitly[X => Y] than so will this: (??? :X) :Y It turns out I was wrong. Backstory: I toyed with an implementation of type unions: private[this] val ...
Turin's user avatar
  • 2,210
3 votes
1 answer
167 views

Scala - Overloading method in implicit class

I currently have an issue where I am trying to overload a method contained within quill using an implicit class, normally this is possible with the simple case, i.e. if you have something like class ...
mdedetrich's user avatar
  • 1,889
3 votes
1 answer
178 views

Finding the second matching implicit

Consider the following setup: trait Foo[A] object Foo extends Priority2 trait Priority0 { implicit def foo1: Foo[Int] = new Foo[Int] {} } trait Priority1 extends Priority0 { implicit def foo2: ...
Alec's user avatar
  • 32.1k
3 votes
0 answers
3k views

Scala implicit parameter not found

I am trying to write this object: object Timed { def apply[T](fn: => T)(implicit logger: Logger): T = measureDuration(Thread.currentThread().getStackTrace.last.getMethodName, TimeUnit....
Frank's user avatar
  • 4,381
3 votes
0 answers
314 views

shapeless calling value on lazy make a StackOverflowError

While learning shapeless via this useful guide I was trying to merge what I have learned from this in this exercice The result is this code : import shapeless._ object GenericV3 { trait ...
crak's user avatar
  • 1,645
3 votes
0 answers
305 views

How do I overload TYPE* conversion from another pointer?

I can't seem to find anything that deals with this type of operation. I have a class TextButton : public TextDecorator class that I want to overload the implicit conversion operator for. The ...
MarcD's user avatar
  • 598
3 votes
0 answers
249 views

Chain implicit conversion of collection

I fail make an implicit conversion List[A] => List[B], given implicit conversion A => B. There is a very related question that has a solution but does not work for me. Also, here is a nice ...
V-Lamp's user avatar
  • 1,668
3 votes
1 answer
1k views

Implicit parameters not found

I'm having some trouble figuring out why compiler complains about not finding an implicit parameter for reads because I'm almost sure that it is in the scope. The error is the following: Error:(13, ...
vicaba's user avatar
  • 2,846
3 votes
2 answers
772 views

Tunnel implicit parameter to call-by-name function body

Consider following code snippet: object Example { def run(f: => Unit): Unit = { implicit val i = 1 f } def caller(): Unit = run { todo } ...
llirik's user avatar
  • 148
3 votes
1 answer
211 views

Implicit search does not guide type inference to find a supertype in Scala

I the following code, I have evidence of R[A] and B is a subtype of A, so I would expect foo to infer the type of A and use the RA evidence. However, scalac refuses to do so. trait R[T] case class A(...
Jonathan Chayat's user avatar
3 votes
3 answers
2k views

How to implicitly inject a value from an outer scope into a Scala trait

I'm trying to define a reusable trait that expects a value to be in an outer scope. I can define the trait inside the outer scope and it will work, but won't be reusable. When I move the trait to a ...
richj's user avatar
  • 7,529
3 votes
3 answers
181 views

Transform (A => (M[B], M[C])) into (A => M[(B, C)])

I don't know the technical terminology for this, but as stated in the title, I'm looking for a function or feature of a typeclass that transforms a function outputting a pair of containers into a ...
Ben Sidhom's user avatar
  • 1,578
3 votes
1 answer
218 views

How to detect implicit commit in MySQL?

I would like to know is it possible to detect broken transactions caused by implicit commit or no. Currently I don't know how to check if transactions in my application works without implicit commit. ...
user3328160's user avatar
3 votes
1 answer
1k views

How to register my navigation app for implicit navigation intents?

I want my navigation-app to be called via implicit intents from other apps. So I guess I need to "register" my app for such navigation-intents in its Manifest. But how exactly can I "register" as a ...
Sorcerer's user avatar
  • 874
2 votes
0 answers
34 views

Extensions methods using implicits do not compile with Scala 3

Following code compiles fine with Scala 2.13.12, but not with Scala 3.3.1: import scala.language.implicitConversions object Types { trait Vector3f implicit class Vector3fOps(v: Vector3f) { ...
Suma's user avatar
  • 33.9k
2 votes
0 answers
50 views

Scala 3 given/implicit resolution doesn't work as expected

I'm working on the Chapter 11 Case Study: CRDTs from the excellent book "Scala with Cats". The code in the book is written using Scala 2, but I've modified it for Scala 3, specifically 3.3.1....
Abhijit Sarkar's user avatar
2 votes
2 answers
2k views

Playwright clicks element (drop down) before it is ready resulting in the drop down not opening

I have a product page containing a product with quantity options. There is a drop down to select the quantities. I want to click this to open it and select an option. The steps are simple: Load page ...
James M's user avatar
  • 31
2 votes
0 answers
132 views

Scala3 implicit conversion not working with opaque types (not true)

EDIT 2 - BEGIN: What I have not verified, and I should have, was if the conversion of my example works for regular types. And it doesn’t neither. So, the title and all my post is surely wrong. Sorry ...
Readren's user avatar
  • 1,054
2 votes
0 answers
864 views

implicit instantiation of undefined template 'std::function::__1::void(int,int)

#include <QApplication> #include <unordered_map> #include <memory> #include <QDebug> #include <functional> template<typename T,typename ...args> class TestClassA { ...
Savner_Dig's user avatar
2 votes
1 answer
89 views

The opposite of compiletime.constValue[T] in Scala 3

If we have a transparent inline def f(...): Boolean = ..., is it possible to convert the result of f to true or false types, assuming the result of f is known at compile-time? I would like to use ...
Koosha's user avatar
  • 1,554
2 votes
0 answers
333 views

Does using Scala implicit classes feature on Spark Dataframe is a monkey patching?

I'm trying to add side-effect functionality to Spark DataFrame by expanding DataFrame class using Scala implicit classes feature for the reason that "Dataset Transform Method" only allows ...
Maor Aharon's user avatar
2 votes
1 answer
112 views

Is it possible to have a sub-trait inheirit a class parameter from another trait?

I am trying to DRY up my code a little bit. I am using Circe to do some decoding. I have several classes and all of them have the form of: import io.circe.derivation.deriveDecoder import io.circe....
CL40's user avatar
  • 588
2 votes
0 answers
224 views

Scala 3 type class fails: given_... is already defined in scope as class

If I try to compile the following code in Scala 3, I get a given_Finder_Needle_*: is already defined as class given_Finder_Needle_* Am I doing something wrong? Is this the right way of implementing ...
Fabio Epifani's user avatar
2 votes
0 answers
58 views

In scala, what can be done to prevent compiler from cyclic summoning of implicit premises? And how to avoid them

I'm writing an implementation for Curry-Howard isomorphism in scala, a family of proofs can be defined as an object implementing the following trait: (the full code repo is uploaded to https://github....
tribbloid's user avatar
  • 3,898
2 votes
1 answer
116 views

How to implement usage site variance in implicits?

Large redaction of the original question: now I present the whole code upfront, without showing the variants explaining my motivation. Apologies for the confusion. I need a simple type class ...
Turin's user avatar
  • 2,210
2 votes
2 answers
674 views

sbt could not find implicit value for parameter valName

I'm using sbt to build some of the riscv boom from the source code, but the sbt complains that it "could not find implicit value for parameter valName: : freechips.rocketchip.diplomacy.ValName". The ...
qqyang10110's user avatar
2 votes
0 answers
2k views

Why does pureconfig not find my implicit readers?

I use double to encode boolean value in a configuration file. PureConfig does not find a way to cast it while reading the configuration. Initial question (see below for edit). Here is some code to ...
AlexisBRENON's user avatar
  • 3,019
2 votes
1 answer
2k views

How to fit data to non-ideal diode equation (implicit non-linear function) and retrieve parameters

Plot of scattered data I need to fit (x,y)-data to an equation with two variables (the x's and the y's) and retrieve the 5 unknown parameters. I am making a script to treat IV-data (current-voltage) ...
Dooba's user avatar
  • 21
2 votes
0 answers
1k views

Why we need explicit exception chaining in Python 3

I have just learned about exception chaining in Python. What I see is, that there are two ways - inplicit and explicit. If I don't do anything special and raise caught exception. Py will automatically ...
user3883586's user avatar
2 votes
1 answer
261 views

How to solve non linear system of array using scipy

I wrote a class with the aims to solve the system of differential equations (given in numpy.array form) , in order to solve the non linear system I'm using the scipy.optimize.fsolve using an example ...
Drudox lebowsky's user avatar
2 votes
0 answers
99 views

Why does extracting and assigning individual tuple values cause a recursive implicit search?

Here's the code to produce this error: build.sbt scalaVersion := "2.11.7" libraryDependencies ++= Seq( "ai.x" %% "safe" % "0.1.0" ) scalacOptions := Seq("-Ytyper-debug") // Only add this if you ...
EdgeCaseBerg's user avatar
  • 2,791
2 votes
1 answer
3k views

Java FTP over TLS/SSL (FTPS- Implicit) Server in Java - Several Error

I am trying to connecting a server with FTPSClient (true implicit), port 990, and it seems the connection is ok, but it says that the file PDF inside cannot be found. String protocol = "TLS"; // ...
DeathGun's user avatar

1
2 3 4 5
7