type-bounds Questions
5
I know that in Java generics when using a type parameter with multiple bounds,the compiler erases the type information to "the leftmost bound" (i.e. the first class/enum or interface that's on the ...
Garold asked 26/12, 2015 at 11:56
2
Solved
I have a trait with a self-type annotation that has a type parameter. This trait is from a library and cannot be modified. I want to pass this trait to a function that will require an upper bound f...
Albania asked 9/9, 2022 at 4:46
1
Solved
I was going through Streams Documentation and had observed that Stream is a typed interface that extends Base Stream with types as T and again Stream <T>
public interface Stream<T> exte...
Oogonium asked 16/4, 2022 at 18:37
2
I have a trait with a large number of associated types. I want a function that uses those associated types on both sides of a where clause bound:
trait Kind {
type A;
type B;
// 20+ more types
}...
Veer asked 10/8, 2021 at 13:52
1
Solved
abstract class IntTree
object Empty extends IntTree
case class NonEmpty(elem: Int, left: IntTree, right: IntTree) extends IntTree
def assertNonNegative[S <: IntTree](t: S): S = {
t match {
ca...
Astrophotography asked 7/5, 2020 at 22:9
2
Solved
I'm looking for some kind of upper bound on a generic parameter T that ensures that T is a trait.
class Foo
trait Bar
def f[A ??? IsATrait] = ???
// f[Foo] Won't compile
f[Bar] // this is fine
...
Nealneala asked 26/5, 2019 at 8:37
1
Solved
Does Delphi support lower / upper type bounds for its generics, e.g. such as Scala does?
I did not find anything about it in the Embarcadero docs:
Overview of Generics
Declaring Generics
Constra...
Root asked 24/9, 2018 at 12:22
1
Solved
(Actually, this question is not directly related to lambdas, but to casts using bounds, so the question marked as duplicate does not provide an answer to this question. You'll find the answer...
Spigot asked 27/6, 2018 at 19:45
2
Solved
Found myself looking at the arc4random_uniform source (http://bxr.su/o/lib/libc/crypt/arc4random_uniform.c)
My question relates to the following line (the comment is their original comment) :
/*...
Patriapatriarch asked 28/5, 2015 at 14:15
2
Solved
I can't understand why the method2 does not compile whereas method1 does compile.
I am using Eclipse with JavaSE 1.7 and I got the following error on method2:
Multiple markers at this line
...
Colima asked 12/5, 2015 at 14:57
2
When type bounds exist on a type parameter, how exactly does Scala determine the type to infer? For example:
def onMouseClicked_=[T >: MouseEvent](lambda: T => Unit) =
setOnMouseClicked(ne...
Daphne asked 30/4, 2015 at 11:35
4
Solved
I'm attempting to write a simple query monad and am having trouble getting my generic type annotations correct.
My first attempt went as follows (vastly simplified for conciseness)
case class Per...
Cowardice asked 30/4, 2013 at 2:33
1
Solved
Suppose I have:
class Bounded[A] {
type apply[C <: A] = C
}
This compiles:
implicitly[Bounded[Any]#apply[String] =:= String]
This fails:
type Str = Bounded[Any]#apply[String]
...with:
...
Southerly asked 6/10, 2014 at 19:15
1
Solved
I have some simple traits (Entity in the example below) that are extended by case classes in my app. I would like to create an EntityMapper trait that provides an interface for handling the case cl...
Bernardina asked 3/9, 2014 at 17:24
4
Solved
I am trying to get my head around covariance in respect with methods creating new immutable types using lower bounds
class ImmutableArray[+T](item: T, existing: List[T] = Nil) {
private val item...
Burkhardt asked 17/10, 2013 at 13:41
1
I am trying to get a better understanding of the following behaviour:
scala> class C[-A, +B <: A]
<console>:7: error: contravariant type A occurs in covariant position
in type >: N...
Cattleman asked 4/6, 2013 at 18:36
3
Solved
I have a compiler error in scala and I don't know what does it refer to:
Assume these declarations:trait Abstract {
type MyType
}
trait AInner
trait A extends Abstract{
type MyType <: AInner
...
Vaenfila asked 8/4, 2013 at 13:31
1
Solved
I am having some trouble motivating the use of type classes in Scala when comparing to upper bounds on types.
Consider the following code:
case class NumList[T <: Complex](xs: Complex*) {
de...
Grimona asked 10/4, 2013 at 13:3
3
Solved
So I've been trying to learn Scala through the twitter Scala school. But I'm currently stuck at one of their type bound examples.
In particular, it's the one where the type is bound to be viewable...
Polygon asked 20/2, 2013 at 15:31
1
Solved
I'm trying to understand Scala's existential types.
Is there any difference between:
def foo[X <: Bar] = 3
and
def foo[_ <: Bar] = 3
or are they something more than just unnamed type p...
Detwiler asked 7/1, 2013 at 19:29
2
Solved
This problem arose in a module I'm writing, but I have made a minimal case that exhibits the same behaviour.
class Minimal[T](x : T) {
def doSomething = x
}
object Sugar {
type S[T] = { def doS...
Kaiserdom asked 27/4, 2012 at 0:34
2
Further to my other question about reduceLeft, the signature of reduceLeft on Seq is
def reduceLeft [B >: A] (f: (B, A) ⇒ B): B
and we can call it with expressions such as
List(1,2,3,4) re...
Arrears asked 3/12, 2011 at 2:4
1
Solved
Can someone explain why the following doesn't compile? I want that BB[A] is also a List[A]. The method body only enforces this view.
scala> def x[A, BB[_] <: List[_]](p: BB[A]) {p: List[A]}
...
Marthmartha asked 27/6, 2011 at 12:36
4
Solved
Is it possible to do something like this in Scala:
class MyTest {
def foo[A <: String _or_ A <: Int](p:List[A]) = {}
}
That is, the type A could be a String or Int. Is this possible?
(...
Acentric asked 24/9, 2010 at 21:5
2
Solved
In Scala variance can be defined with variance operators like + and - on the generic type argument. For example the List type is covariant in the standard library.
class List[+A]
So a function w...
Ladylike asked 8/9, 2010 at 0:1
1 Next >
© 2022 - 2024 — McMap. All rights reserved.