Questions tagged [implicit]

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

Filter by
Sorted by
Tagged with
2 votes
1 answer
46 views

"Deferred inline method `foo` in trait `Foo` cannot be invoked": Pairs

I was just experimenting with the behavior of givens and inline in Scala 3.2.2, and ran into the following example: trait Max[X]: inline def max(a: X, b: X): X inline given maxForDoubles: Max[...
5 votes
1 answer
105 views

How to summon a `given` member?

Suppose that I have some typeclass trait FooBar[X] and an instance of FooBar[Int]: given intIsFooBar: FooBar[Int] = new FooBar {} Now, suppose that I have an interface Intf that has some member type ...
1 vote
1 answer
47 views

Type negation in Scala 3

Is it possible to implement fail proof Not[A] type in Scala 3? Here is a question asked some years ago: how-can-i-have-a-negation-type-in-scala. Unfortunately, a solution based on 'not given A <:&...
  • 2,199
0 votes
0 answers
14 views

.net CLI authenticate with Auth0 OAuth implicit flow

I am looking for a solution to authenticate a .NET Core CLI with Auth0 OAuth using the implicit flow. My understanding is that this flow launches the Auth0 login page, where the user can enter their ...
0 votes
2 answers
65 views

In scala 3, is it possible to make covariant/contravariant type constructor to honour coercive subtyping?

This is a simple example: object CoerciveCovariance { trait Cov[+T] def cast[A, B](v: Cov[A])( implicit ev: A <:< B ) = { v: Cov[B] } } It doesn't compile: ...
  • 4,747
0 votes
1 answer
48 views

How to define induction on natural numbers in Scala 2.13?

Consider the following definition of natural numbers. sealed trait Nat final case object Z extends Nat final case class S[N <: Nat]() extends Nat And the following definition of vectors. sealed ...
  • 72.2k
0 votes
1 answer
75 views

Has no implicit type error while reading variable with intent attribute

I'm new to Fortran. I'm trying to write a simple module and then test it in the main program. But, this error happens: symbol 'side2' has no implicit type. The same happens for 'side1' and 'hypo'. I ...
2 votes
1 answer
92 views

Scala: implicit type transformation with condition on value

The task is to perform transformation from string value to Int or BigDecimal, depends on string value length. For example, if stringValue > 10 => stringValue.toInt, else => BigDecimal(...
  • 894
0 votes
0 answers
46 views

Scala implicit resolution for type (in)equality

The following code import shapeless._ // =:!= class G[T1] { def as[T2](implicit ev: T1 =:= T2): Unit = ??? def as[T2](implicit ev: T1 =:!= T2): Unit = ??? } val g = new G[Int] g.as[Int] ...
0 votes
1 answer
32 views

How to define a implicit (given) Conversion for Generic Types?

I want to use the Scala 3 Implicit Conversion. I have the following construct that I want to migrate: implicit def toTesterObjectScenario[In <: Product]( ...
  • 13.9k
0 votes
0 answers
35 views

Evaluate expression of implicit TypeTag on Intellij debugger fails, why? and how can i enable it?

package spark.course.example import org.apache.spark.sql.SparkSession import org.apache.spark.sql.functions.typedLit object Example extends App{ val spark: SparkSession = SparkSession.builder....
  • 1
0 votes
1 answer
36 views

Correct way to specify inline implicit ordering

Let's say I've got a case class definition: // Scala 2.13 case class Employee(name: String, id: Int) Then I'd like to specify an inline implicit ordering like: es.sorted(implicit ord: Ordering[...
1 vote
1 answer
55 views

Shapeless - How to derive LabelledGeneric for Coproduct

I'm trying to generate LabelledGeneric for Coproduct, so that it can be used instead of typical sealed trait hierarchy. So far I was able to do it by explicit specification of labels for ...
0 votes
1 answer
54 views

How can I implement Fractional[Int] and get access to new arithmetic operations

I am trying to create a Fractional[Int] instance in Scala 3 that I want to use for finite field arithmetic. I have a class whose instances can work as Fractional[Int] implementations: class IntModp(...
0 votes
1 answer
41 views

In Scala 2.13, why is it possible to summon unqualified TypeTag for abstract type?

Considering the following code: import scala.reflect.api.Universe object UnqualifiedTypeTag { val RuntimeUniverse = scala.reflect.runtime.universe trait HasUniverse { val universe: ...
  • 4,747
0 votes
1 answer
75 views

How to write an implicit Numeric for a tuple

I have a scenario where I would like to call sum on a sequence of (Double, Double) tuples. Ideally I would like to do something like the following: implicit def toTupleNumeric[T](num: Numeric[T]) = ...
  • 4,875
0 votes
2 answers
136 views

Scala how to derivate a type class on a trait

In the following example I would like to be capable to use an implicit type class - Process - wit a trait as input. But the compilator does not recognize any implicit in that case. I was expecting as ...
  • 35
1 vote
1 answer
107 views

Scala: how to use an implicit class extension's implementation of a trait

I am trying to provide an extension to a class I can't modify using an implicit class. I have a trait HasFoo[A] that takes a type parameter. I then have a class (Processor) that expects an A that ...
  • 674
1 vote
0 answers
86 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 ...
  • 913
0 votes
0 answers
58 views

Is there a performance penalty for scala functions with implicit parameters?

The code below shows consistent results on my machine: the code without implicits performs better case class Config(appName: String, timeout: Int) def appendWithImplicit(str: StringBuilder)(implicit ...
0 votes
0 answers
65 views

Is it possible to implicitly cast a generic type?

I'm working with a function that takes a list of email address records and returns the appropriate one for the use case. This list is passed to the function as an List[Map[String, String]], and the ...
3 votes
3 answers
112 views

Rounding through type ascription

I would like to introduce a custom class, say Decimal2, so that I would be able to round through type ascription: val x: Decimal2 = 1.2345 // 1.24 So far I've tried this: class Decimal2(val value: ...
0 votes
0 answers
48 views

Behavior of implicit declaration declared after usage

Scala 2.13.10. Consider the following code: object Hello extends App { def foo(implicit i: Int) = println(i) foo implicit val i: Int = 42 foo } It compiles with the warning Reference to ...
  • 8,263
0 votes
1 answer
97 views

Scala implicit class based on type class

implicit class IntIncrement(val underlying: Int) extends AnyVal { def increment(): Int = underlying + 1 } This is valid and allows me to do something like 1.increment() I want to be able to ...
  • 719
1 vote
1 answer
75 views

How can I make an implicit field, transient?

I want to set up doobie inside the AsyncFunction of apache Flink but it needs an implicit read instance of output. on the other hand, I can not send Read[Out] as an implicit parameter because the ...
1 vote
1 answer
30 views

Returning functions that check for equality/ordinal comparison for any valid type parameter

I'm not very experienced with using Scala and I think I'm missing something when it comes to implicits. I'm essentially trying to take an enumerated argument that represents a certain logical operator ...
0 votes
1 answer
49 views

Calling a generic scala method in groovy

I am trying to call a method from an external scala library in a groovy class. The library method has the signature: def ofType[T: ClassTag](bundle: Bundle): Iterable[T] The call ofType<Data>(...
  • 3
2 votes
2 answers
36 views

Very strange implicit constructor calls when calling method [duplicate]

The following program compiles perfectly, even though the method "m", which is supposed to receive an instance of C, is called with an integer or a float. class C { public: const int value;...
1 vote
1 answer
81 views

Diverging Implicit Error When Parsing JSON to Case Class in Scala

I'm facing a strange error where I'm trying to parse a JSON String into a generic case class. My case class looks like this: final case class LocationAPIObject[F[_]]( countryCode: F[String], ...
  • 13.4k
0 votes
1 answer
56 views

How does the implicit conversion for int2double come in scope

The following conversion works because of int2double implicit conversion scala> val d: Double = 2 d: Double = 2.0 prior to 2.10, this implicit conversion was part of Predef object and was thus ...
0 votes
1 answer
124 views

sparkpb UDF compile giving "error: could not find implicit value for evidence parameter of type frameless.TypedEncoder[Array[Byte]]"

I'm a scala newbie, using pyspark extensively (on DataBricks, FWIW). I'm finding that Protobuf deserialization is too slow for me in python, so I'm porting my deserialization udf to scala. I've ...
0 votes
1 answer
27 views

Contextbound "Temporal" causes: "Cannot resolve symbol flatMap"

I have something like def test[F[_]: Sync: Console](counter: Int): F[Unit] = for { _ <- if(counter % 10000 == 0) Console[F].println(s"counter: ${counter}") else Sync[F].unit _ &...
  • 11
0 votes
1 answer
72 views

How to Plot Implicit Equation in Python

I want to Plot V(y axis) vs t(x axis) graph using the below equation at 5 different values of L(shown below) L= [5,10,15,20,25] b=0.0032 Equation, (b*V*0.277*t) - (b*L) = log(1+b*V*0.277*t) code ...
0 votes
1 answer
28 views

'method Invocation failed' recently began occurring for processing a system.object

I was wondering if there was some sort of update to PowerShell that would have caused the following to begin throwing invocation failed because it stopped implicitly recognizing objects as strings. ...
1 vote
0 answers
229 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 { ...
0 votes
1 answer
80 views

What does `import ev._` for implicit evidence mean, and when should I use it?

the Arithmetic.scala is: package Arithmetic // The Arithmetic typeclass which implements various arithmetic operations on custom datatypes abstract class Arithmetic[T <: Data] { implicit def cast(...
1 vote
2 answers
102 views

Why the Scala compiler can provide implicit outside of object, but cannot inside?

The title might be quite vague, but here is the code: https://github.com/amorfis/why-no-implicit So there is a tool to transform Map[String, Any] to a simple case class. The tests pass and this piece ...
  • 15.2k
1 vote
1 answer
94 views

How to derive a Generic.Aux if the case class has a type parameter - Shapeless

given: sealed trait Data final case class Foo() extends Data final case class Bar() extends Data final case class TimestampedData[A <: Data](data: A, timestamp: Long) Is there a succint way to ...
  • 101
0 votes
1 answer
133 views

Scala 2.13: Case class with extendable variable attributes?

I want to create a case class which can incorporate a record of string and another case class entity. For example: case class Student( name: String age: Int ) case class Example( [key:String]: Student ...
  • 3,578
1 vote
1 answer
67 views

Scala : Add an implicit method to transform case class to another case class in alias object?

I am new to Scala and I have a case class like this: case class Student( name: String, age: Option[Int] = None, id: String ) and another case class like this: case class Member( id: String, `...
  • 3,578
2 votes
1 answer
276 views

Type parameter for implicit valued method in Scala - Circe

I'm new to Scala, and using circe to model and serialize some API responses. I find myself using the following boilerplate sealed trait SomeTrait object SomeTrait { implicit val someEncoder: ...
1 vote
2 answers
249 views

Why is the spark.implicits._ import not helping with encoder derivation inside a method?

So, importing an implicit member from a created instance works as expected, object Test extends App { class Bag { implicit val ssss: String = "omg" } def call(): Unit = { val ...
  • 13.6k
0 votes
0 answers
36 views

How to simulate widening of standard value types through implicit conversions?

If I add a Byte and a Char, the result is an Int. If I put a Squirrel and a Hamster in a List, it becomes a List[Rodent]. I would like to generalize this principle on a meta level through type classes....
  • 2,199
0 votes
0 answers
40 views

How is implicit cursor implemented in SQL?

What is the internal implementation of implicit cursors? For example, when DML statements are executed, what happens behind the scenes whenever an implicit cursor is being created? And how the ...
0 votes
0 answers
36 views

No implicit arguments of type: Zero[DenseVector[Double]] [duplicate]

Since I have upgraded Breeze library from version 1.0 to version 2.1.0 I cannot create a DenseMatrix[DenseVector[Double]] I got the following error: No implicit arguments of type: Zero[DenseVector[...
  • 13
1 vote
2 answers
65 views

SYB `mkT` function in Scala

Continuing on from a previous question of mine, I am attempting to implement Scrap Your Boilerplate in scala 3 and am running into an issue now with the mkT function described in the paper. Given the ...
  • 695
0 votes
1 answer
52 views

SYB `cast` function in Scala

I am reading the Scrap Your Boilerplate paper and trying to follow along by implementing the ideas in scala as best I can. However, I'm stuck on the very first function, the cast, which is used to ...
  • 695
0 votes
1 answer
34 views

Is there a way i can add implicit ordering to improve this code?

sealed trait BinaryTree[+A] case object Leaf extends BinaryTree[Nothing] case class Branch[A](value: A, leftTree: BinaryTree[A], rightTree: BinaryTree[A]) extends BinaryTree[A] object BinaryTree ...
0 votes
1 answer
69 views

Type inference of higher-kinded type argument identity in scala

I have a type class trait ResponseHandler[+A, -B[_]] { def handle[C](response: WSResponse, parser: A => B[C]): HTTPCallResult[C] } and its instance type Identity[X] = X implicit object ...
0 votes
2 answers
66 views

Can't create Breeze DenseMatrix with Scala3

When trying to create a dense matrix of type Option with Scala 3 I receive an error. val dm1 = DenseMatrix((1,2),(1,2)) // <- this works val dm2 = DenseMatrix((Some(1),Some(2)),(Some(1),Some(...
  • 85

1
2 3 4 5
36