type-parameter 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

2

Solved

In the following code I have a token type that contains a literal value. By using an empty interface I can create a slice of tokens and append tokens that have different types. I don't think it's p...
Ametropia asked 24/2, 2022 at 5:32

1

Solved

I'm trying out go generics in 1.18beta2 and I'm trying to write an abstraction layer for key/value store, boltdb. This is what I'm trying to achieve with it. type Reader interface { Read(buc...
Stubborn asked 15/2, 2022 at 19:15

1

Solved

type Number interface { int | int64 | float64 } type NNumber interface { } //interface contains type constraints //type NumberSlice []Number type NNumberSlice []NNumber func main() { var b in...
Cashbook asked 10/2, 2022 at 23:6

1

Solved

Consider the experimental package slices. The package is experimental, so I understand the signatures may change; I'm using it to illustrate the issue. Consider the signatures of two functions from...
Contributor asked 10/2, 2022 at 10:42

3

Solved

The Collections.fill method has the following header: public static <T> void fill(List<? super T> list, T obj) Why is the wildcard necessary? The following header seems to work just as...

1

Solved

As an exercism exercise, I'm currently trying to filter an iterator according to whether the value is even in order to produce a new iterator. My function currently looks like: pub fn evens<T&gt...
Wardwarde asked 2/9, 2021 at 14:48

1

Solved

I am calling a library method that returns a raw Stream. I know the type of the elements in the stream and want to collect into a collection with the declared element type. What is the nice, or the...

5

Solved

I noticed something while I was derping around with generics. In the example below, doStuff1 compiles but doStuff2 doesn't: public <T extends Foo> void doStuff1(T value) { Class<? extend...
Nephrolith asked 9/8, 2013 at 10:22

1

Solved

Consider method f which is parameterised by a type constructor F[_] and a proper type A def f[F[_], A](v: F[A]) = v Lets try to apply it to new Bar scala> class Bar class Bar scala> def ...

2

Solved

In Haskell, I can define a Tree: data Tree a = Empty | Node a (Tree a) (Tree a) How could I write this in Scala? I'm not sure how to keep the type parameter [A] in Scala for Node to match Tree...
Stockbreeder asked 1/11, 2014 at 13:51

1

Solved

Why does pattern matching work differently when type parameter comes from an enclosing method as opposed to an enclosing class? For example, trait Base[T] case class Derived(v: Int) extends Base[I...
Wanids asked 5/3, 2020 at 21:19

2

Solved

I needed some help understanding recursive generics in C#. I came across this code: public abstract class Value<T> where T : Value<T> { .... } public class UserId: Value<UserId&g...
Clower asked 8/10, 2019 at 18:36

1

Solved

Consider the following example: import kotlin.reflect.KProperty1 infix fun <T, R> KProperty1<T, R>.test(value: R) = Unit data class Foo(val bar: Int) fun main() { Foo::bar test "He...
Supersonic asked 1/8, 2019 at 23:27

2

Motivation I have an Either<L, R> class, which represents a value of one of two types, or semantically different states. In some cases, it is valuable to operate on it no matter which alterna...
Arrester asked 16/6, 2019 at 11:32

1

Solved

I am trying to define a method in scala that takes a generic type of S[_] <: Seq[Double] and returns a S[FixedLoad] (FixedLoad is a concrete type). But my implementation gives me errors and I ca...
Cutout asked 21/5, 2019 at 14:24

2

Solved

When having a parametrized type: data A a=X a| Y I have tried (successfully) implementing Functor and Applicative without specifiying the type parameter: instance Functor A where instead of insta...
Conjuration asked 15/5, 2019 at 7:1

2

Solved

I'm trying to define a callback function that needs to accept a generic parameter and return a value of the same type. Keep in mind that the following example is an oversimplified version of what I...
Drumfish asked 25/4, 2019 at 11:17

2

Solved

I have an abstract Event class which has an abstract method: abstract boolean intersect(Event object); This method should check if two instances of an Event subclass intersect based on the insta...
Roa asked 5/11, 2018 at 5:7

5

Solved

I want to use an abstract type rather than a type parameter. In my generic classes constructor, I want to have a parameter of the generic type, but the code doesn't compile: class SomeOtherClass(...
Greenlee asked 7/8, 2012 at 11:33

1

Solved

I find it annoying that one has to specify the types of both Foo and FooFactory in the call to RunTest below. After all, if the test knows the type of the Factory, the type the Factory is creating ...
Roentgenograph asked 16/1, 2018 at 18:15

1

Solved

I have the following struct: #[derive(Debug)] pub struct Entry { pub index: usize, pub name: String, pub filename_offset: u64, pub entry_type: EntryType, } #[derive(Debug)] pub enum EntryType...
Ammo asked 5/1, 2018 at 20:24

1

Solved

In the example below (only for demo purpose), if T is not constrained with class, then this conversion: var ret = objectA as T; ..will cause the following compile error: The type parameter '...
Angi asked 5/1, 2018 at 7:31

4

Ok, I have a number of different classes deriving from a base class. This base class is an abstract containing commom methods. One of the methods is a Copy method, wich should be present in all de...
Loxodrome asked 2/7, 2013 at 17:45

© 2022 - 2024 — McMap. All rights reserved.