Questions tagged [given]

Questions regarding the `given` instances.

Currently, the tag is intended primarily for questions about the resolution of Scala 3 Given instances and the given-syntax.

8 questions
7
votes
1 answer

Problem with given instances writing MTL style code with Scala cats

I am trying to write some Scala code to have custom behaviour in an mtl style. For example, in order to expose the "write to DB" functionality abstracting over the specific effect I wrote my own type class: trait CanPersist[M[_]]: def…
5
votes
1 answer

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 A and also guarantees that there is a given…
Andrey Tyukin
  • 43,673
  • 4
  • 57
  • 93
5
votes
1 answer

Scala3 "as" and "with" keywords used with "given"

Currently learning about Scala 3 implicits but I'm having a hard time grasping what the ​as and with keywords do in a definition like this: given listOrdering[A](using ord: Ordering[A]) as Ordering[List[A]] with ​def compare(a: List[A], b: List[A])…
greenTea
  • 204
  • 2
  • 7
2
votes
1 answer

"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[Double] with inline def max(a: Double, b: Double)…
Andrey Tyukin
  • 43,673
  • 4
  • 57
  • 93
1
vote
1 answer

Hidden bugs with given-when and for-match. Is Perl truly cross-platform?

I have been trying to make a relatively large Perl program that has been working perfectly fine on CentOS for many years to work on Ubuntu and this has become a huge nightmare. CentOS uses Perl built for x86_64-linux-thread-multi and Ubuntu uses the…
FNia
  • 173
  • 6
0
votes
1 answer

Why can't the compiler chain conversions?

Let T1, T2, T3 be three types. We also define two given instances of the Conversion class so that the compiler can go from T1 to T2 and from T2 to T3. The following code then compiles fine: type T1 type T2 type T3 given Conversion[T1, T2] with …
t9dupuy
  • 330
  • 1
  • 2
  • 9
0
votes
1 answer

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(val p : Int) extends Fractional[Int] { def…
0
votes
0 answers

Can I express `T =:= obj.MyType forSome { val obj :MyClass }`, either as type bounds or through givens in Scala 3?

Lets say I have a unary evidence type constructor class MyEvidence[T] object MyEvidence { //statically provable implicit/given values for various type arguments. } Now let us have urelated classes trait MyClass { type MyType; val myVal…
Turin
  • 2,208
  • 15
  • 23