type-members Questions

1

Solved

I have this program: object B{ def apply[T](c:T)={} } object C{ type T def apply(c:T)={} } object A extends App{ val d=B{println(1);2} val e=C{println(1);2} } the line val e = C{println...
Godber asked 3/12, 2019 at 0:39

4

Solved

I am learning Scala and I was trying to create a type class to solve the "Every animal eats food, but the type of food depends on the animal" problem. I have an Eats type class with context bounds:...
Salchunas asked 13/7, 2019 at 10:14

2

Solved

Scala has a nice feature to infer type parameter inside the pattern match. It also checks pattern match exhaustiveness. For example: sealed trait PField[T] case object PField1 extends PField[Str...
Catton asked 9/8, 2018 at 12:5

2

The following piece of code does not compile : trait A[F] { def find(x: Int): F def fill(f: F): Unit } object TestA { def test[T <: A[F] forSome { type F }](t: T) = t.fill(t.find(0)) } I...
Flea asked 21/2, 2015 at 18:2

1

This works well class MyClass[T<: Actor: ClassTag] extends Actor { //.... } but this doesn't due to the error No ClassTag available for MyClass.this.T class MyClass extends Actor { type T&...
Ardene asked 14/12, 2013 at 6:43

1

Solved

How would I convert: trait Foo[A <: Foo[A]] to a type member? I.e., I want something along the lines of the following: trait Foo { type A <: Foo {type A = ???} } but I am having diffi...

2

Solved

What works (Part A) Suppose I have a trait with a type parameter: trait A[T] I can use an existential type to write a method that will take a collection of As that all have the same T: def foo...
Foresheet asked 21/8, 2012 at 1:31
1

© 2022 - 2024 — McMap. All rights reserved.