abstract-type Questions

5

Solved

I was reading A Tour of Scala: Abstract Types. When is it better to use abstract types? For example, abstract class Buffer { type T val element: T } rather that generics, for example, abstra...
Anticathode asked 20/7, 2009 at 16:30

1

This code does not compile in Scala 3 since type projection on an abstract type is now invalid: trait Entity: type Key type Dictionary[T <: Entity] = Map[T#Key, T] The compiler complains tha...
Super asked 24/1, 2023 at 20:47

1

I have a simple case to test the type inference capability of scala: trait Super1[S] { final type Out = this.type final val out: Out = this } trait Super2[S] extends Super1[S] { final typ...

2

Solved

I am supposed to make a program based on a header file and some further description. The problem working with opaque type is needed. Opaque struct is declared in header file with some other functio...
Nabal asked 16/4, 2019 at 12:43

2

Solved

I have the following simple program that defines 2 identical upper bounds for type parameter and abstract type alias respectively: package scala.spike.typeBoundInference object Example1 { trait ...

1

Solved

assuming I have an abstract type AA and concrete type XXX: trait AA { type A = XXX final type B = XXX } In this case in any subclass of AA, both type A and B cannot be overriden, so it appears...
Theologue asked 13/3, 2019 at 21:54

1

Scala allows to define types using the type keyword, which usually have slightly different meaning and purpose depending on when they are declared. If you use type inside an object or a package ob...
Ganda asked 10/1, 2019 at 21:59

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

3

How do I get the subtype of an instance of an parametric type in julia? For example: immutable Dog{T <: Number} snout::T end dog = Dog(5.) typeof(dog) ...returns Dog{Float64}. Is there a wa...
Apogeotropism asked 14/7, 2015 at 20:52

1

I want to convert F bounded polymorphism to abstract type members. trait FBoundedMovable[Self <: FBoundedMovable[Self]] { def moveTo(pos: Vect2): Self } to trait Movable { self => ...

2

Solved

Consider this code (which is kind of type safe units): abstract class UnitsZone { type ConcreteUnit <: AbstractUnit abstract class AbstractUnit(val qty: Int) { SOME_ABSTRACT_MEMBERS def +(...
Chaqueta asked 5/8, 2014 at 22:19

4

Solved

I need a way to enforce a method in an abstract class to have a return type of the concrete class of the object it is called on. The most common example is a copy() method, and I'm currently using ...
Homily asked 6/2, 2013 at 13:14

2

While cracking my head over another question, I came across different riddles which seem related. This is one of them: trait Sys[S <: Sys[S]] { type Peer <: Sys[Peer] } trait Fenced { typ...

1

Solved

scala> class A { type T <: String; def f(a: T) = println("foo")} defined class A scala> (new A).f("bar") <console>:9: error: type mismatch; found : java.lang.String("bar") req...
Joyce asked 30/6, 2012 at 13:45

1

Solved

Given the code below the method foo should compare operator-wise a given parameter bar with the lowerBound and upperBound all being of the same abstract type Bar. trait Foo { type Bar <: Order...
Spindling asked 13/2, 2012 at 0:11

2

Solved

I'm trying to wrap my head around abstract and explicit self types in scala. Lets consider this example: I want to create a base for extensible tree as simple as this: trait Tree { def children:...
Marylnmarylou asked 8/2, 2012 at 17:39

1

Solved

Given the following code: class A { class B type C <: B trait D } class E extends A { type C = B } class F extends E { override type C = B with D } Why does the Scala IDE's pre...
Audiophile asked 7/1, 2012 at 16:38

3

Solved

There are two possible way to express abstraction over types. abstract class Buffer { type T val element: T } rather that generics, e.g. abstract class Buffer[T] { val element: T } I under...
Skid asked 30/9, 2011 at 21:0

2

Solved

I couldn't find the answer to this in any other question. Suppose that I have an abstract superclass Abstract0 with two subclasses, Concrete1 and Concrete1. I want to be able to define in Abstract0...
Depopulate asked 30/11, 2010 at 11:18

1

Solved

In what situations should abstract types be preferred over type parameters?
Casimiracasimire asked 3/7, 2010 at 8:24

2

Solved

I am trying to use the answer of a preceding question to implement a small graph library. The idea is to consider graphs as colections, where vertices wrap collection elements. I would like to use...
Arteritis asked 14/1, 2010 at 19:13
1

© 2022 - 2024 — McMap. All rights reserved.