Questions tagged [abstract-type]

A type without instances or without definition. An abstract type may provide no implementation, or an incomplete implementation.

4
votes
3answers
105 views

Understanding Scala use of abstract types and Classes

The next code does not compile. Why can't Santorin eat HorseFood? Tornado is declared as a new Horse, and Horse is a subtype of Animal, yet it can "eat" HorseFood. import scala.io.StdIn._ import ...
0
votes
2answers
286 views

Can a scala type class have abstract type members?

I have this type class: sealed trait DbValueOps[T <: DbValue] { type R def apply(newContent: R): Option[T] def fromString(newContent: String): Option[T] def isValidContent(newContent: R): ...
-1
votes
2answers
60 views

How to include opaque type in multiple .c files?

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 functions. ...
6
votes
1answer
252 views

Scala: Difference between 'type A = XXX' and 'final type A = XX'?

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 ...
1
vote
2answers
73 views

What does 'do not conform to trait Builder's type parameter bounds' mean in scala?

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 ...
4
votes
1answer
90 views

What is the meaning of a type declaration without definition in an object?

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 ...
0
votes
0answers
47 views

consume the abstraction defined in Coq for building richer type in C++

Is there a way to extract an abstractions defined in Coq and link it with C++ code? For example, I want to define a Type named EvenNum, which represents all the even natural numbers. Is there any ...
1
vote
1answer
57 views

Abstrac type and path dependent type in scala

I'd like to use abstract type and type refinement to encode something like a functional dependency between two types. trait BaseA { type M type P <: BaseB.Aux[M] def f(m: M): Unit } trait ...
0
votes
1answer
81 views

Referring to abstract type outside of trait for class construction

Premise: I want to separate the information necessary to instantiate a class from the information necessary to "run" the class. However, the information neccesary to "run" the class may differ from ...
0
votes
0answers
127 views

Pattern matching on a generalised ADT and abstract type does not compile

I found something curious in scala that I can't quite explain. I've got a generalized algebraic data type (DbType), and a trait FieldAdapter with an abstract type U and a member dbType of type DbType[...
0
votes
1answer
44 views

load cities in choiceType after select one gouvernorat in a second ChoiceType

I have two entities with association Gouvernorat -> Villes. This is the Gouvernorat entity: class Gouvernorat { /** * @var int * * @ORM\Column(name="id", type="integer", ...
3
votes
1answer
147 views

Higher kinded type constructor with upper type bounds doesn't work if bound is abstract type member

I want to define a trait that is parameterized by an upper bound R and a higher kinded type constructor F[_] that accepts only arguments that are subtypes of R. I want that this trait implements a ...
1
vote
1answer
48 views

Abstract parametric types in Scala

I have: trait A[B[_]] and I have: trait Base { type AImpl <: ??? def foo: AImpl } so that the classes extending Base would define A and implement methods and fields. ie: trait BB[T] ...
0
votes
1answer
66 views

Abstract type, variables and typeclasses in Scala

I'm trying to make a typeclass that depends on user input. Imagine we have some case objects: sealed trait H case object Ha extends H case object Hb extends H and the type class: trait Foo[A] { ...
1
vote
0answers
206 views

Deserialize jackson with abstract Type

I'm a beginner in java so i'm not really sure if the title is right but i've been trying to unmarshal a json string of which i won't know the type in advance. public interface Dummy<T> { ...
1
vote
2answers
128 views

How to instruct Scala not to upcast abstract type?

Considering Bulldog: trait Animal { type Food def defaultFood(): Food } class Bulldog extends Animal { type Food = Steak ... implementations ... } The function Bulldog.defaultFood() works ...
1
vote
2answers
72 views

Why is the best way to avoid being trapped by Scala's abstract type refinement?

I have a basic example from chapter 20.7 of Programming in Scala (Martin Odersky, Lex Spoon and Bill Venners), on the topic of Abstract Types. The code below is from Listing 20.10, except that I ...
1
vote
1answer
213 views

Undefined reference on function operator>>

I'm defining a Abstract data type, when I started to define operators, I'm getting this error, do not understand why other similar projects my operators work and not on this one. EventoHistorico.h #...
0
votes
1answer
159 views

Scala Abstract Typing with Tabulate

I am trying to make a generic repVec function similar to Matlab's repmat function using Scala Breeze. First I tried: def repVec[T](in: DenseVector[T], nRow: Int): DenseMatrix[T] = { DenseMatrix....
0
votes
1answer
275 views

Curiously recurring template pattern constraints with Scala abstract types

I have a Scala compiler error puzzle that I can't figure out. For reasons not given here, I need to declare my classes using the curiously recurring template pattern. Some of my classes need to ...
0
votes
2answers
110 views

In Scala, How to reference the ClassTag of implemented abstract type in all subclasses?

If I have 1 trait and 2 objects: trait MyClass { type T <: MyClass def foo(): ClassTag[T] = {...} } object ChildClass1 extends MyClass { type T = String } object ChildClass2 extends ...
0
votes
1answer
353 views

Type mismatch with abstract types

I'm using abstract types and having problems getting Scala compiler to unify two types that should be the same. These are my definitions: trait Chromosome { type Gene val size : Int def apply(...
4
votes
2answers
543 views

Scala Abstract type members - inheritance and type bounds

I ran into some strange situation in Scala today while I tried to refine the type bounds on an abstract type member. I have two traits that define bounds on a type member and combine them in a ...
2
votes
2answers
401 views

Abstract types + self types + type overriding, and error “Value xxx is not a member of Component.this.T”

The error is illustrated in the following: trait Base { type T } trait Component { self: Base => override type T <: MyT val factory: Factory trait Factory { def get_t: T } trait ...
2
votes
0answers
50 views

Why does unimplemented abstract type compile in scala? [duplicate]

Consider the following simple example: trait Foo { type Bar } class Baz extends Foo // <-- no compile error I don't understand how the last statement compiles when clearly type Bar wasn't ...
2
votes
1answer
105 views

Trait with Abstract Type in Method Argument

I am new to Scala and am building tools for statistical estimation. Consider the following: a trait probabilityDistribution is defined, which guarantees that classes which inherit from it will be able ...
6
votes
3answers
99 views

How to extract the specific type from an instance of a generic type in julia?

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 ...
1
vote
1answer
317 views

Pattern Match Abstract Type Trait Member

sealed trait Foo { type T <: Option[Any] val x : T } case class Bar(x : Option[Int]) extends Foo { type T = Option[Int] } val baz : Foo = Bar(Some(42)) baz.x match { case Some(a) =&...
0
votes
0answers
287 views

Symfony 2 - Custom Form Field Type with multiple parent

I would like if you have an idea to create a custom form field with two parents ? I am trying to create a select2 form type. But I would like to use this type for entity type and choice type. I know ...
1
vote
1answer
208 views

How to override “=”

I was looking into Haxe abstracts and was very interested in building an abstract that would wrap a class and unify it to, in my case, an Int. @:forward() abstract Abs(Op) { public inline ...
1
vote
1answer
109 views

Scala Abstract Type Member

I noticed that I can instantiate a scala trait with an abstract type member. The code below compiles. But what is the t.B? trait A { type B } val t = new A {}
0
votes
2answers
114 views

Scala: access “static” member of bounded generic type

I want to achieve the following: abstract class Super { def typeSpecific: Int } class SubA extends Super { def typeSpecific = 1 } class SubB extends Super { def typeSpecific = 2 } class ...
0
votes
1answer
134 views

Scala class check at runtime

I have this use case i cannot solve. I thought of an environment for message passing programming. There are two main concepts, Things and Environment: Things are like real world Things they can be ...
3
votes
2answers
87 views

Referring abstract type member of a type parameter

My scenario is like: trait A { type B def foo(b: B) } trait C[D <: A] { val d: D def createB(): D#B def bar() { d.foo(createB) } } In REPL, it complains <...
0
votes
2answers
209 views

Want runtime polymorphism while using type parameter or generic?

The following is a story about "animal eats food", and there is a cat eating a fish. class Food abstract class Animal { type F def eat(food: F) } class Fish extends Food class Cat extends Animal {...
1
vote
1answer
57 views

Advise on exercise with scala abstract types

I'm looking for an advise on this exercise I'm doing - specifically, what areas can be improved/shortened? I don't like that to feed the animals I have to use asInstanceOf but cannot find a better way....
6
votes
1answer
460 views

Expressing a F bounded type as abstract type member [duplicate]

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 => type ...
0
votes
1answer
244 views

scala: reflection on an inner class of abstract type

I want to reflect an inner class of abstract type in a trait. Something like this: import scala.reflect.runtime.{ universe => ru } import scala.reflect.ClassTag import scala.reflect.api....
1
vote
1answer
408 views

Scala: typeTag for an abstract type?

I want to do something like the following: trait Sim { type Probe var probe: Probe def reflectProbe() { // works: val tt_int = scala.reflect.runtime.universe.typeTag[Int] ...
2
votes
1answer
121 views

Using case object to satisfy abstract type member

I have an architecture where I have a concept of a Component that is instantiated dynamically at run-time from a static configuration and/or run-time data. The static part of the data is provided as a ...
5
votes
2answers
176 views

Returning the same type from abstract trait method

Lets say we have a trait, that has some values and some operations on them. trait Foo { type Self <: Foo val x: Int def withX(x: Int): Self } This is implemented using abstract types. We ...
0
votes
2answers
197 views

Find implicit value by abstract type member

With a type like trait A[T], finding an implicit in scope is simply implicitly[A[SomeType]] Can this be done and, if so, how is this done where the type-parameter is replaced with an abstract type ...
3
votes
2answers
3k views

How to reference outer object from inner class in Scala

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 ...
1
vote
2answers
116 views

Why is this an invalid use of Scala's abstract types?

I have this code: class A extends Testable { type Self <: A } class B extends A { type Self <: B } trait Testable { type Self def test[T <: Self] = {} } object Main { val h = ...
1
vote
1answer
57 views

Why is this invalid Scala?

I'm working with abstract types, and I'm wondering why this is invalid: class A {} class B extends A {} class X {type T = A} class Y extends X {override type T = B} Seeing as B <: A, why can't I ...
0
votes
2answers
315 views

Scala abstract types in classes within objects

If I do this: object Parent { class Inner extends Testable { type Self <: Inner } def inner = new Inner() } object Child { class Inner extends Parent.Inner { type Self <: Inner } ...
1
vote
1answer
359 views

XSD in Altova XMLSpy 2014: Why can I use an abstract type in a concrete element?

In Altova XMLSpy 2014, I have a XSD document that defines: An abstract type, "t_abs". A concrete type, "t_con", defined as a sequence of elements, and one of the elements is defined as type "t_abs". ...
1
vote
2answers
75 views

TypeTag for a type containing an abstract type

We have a trait Foo and are thinking about a method cast that takes a type parameter A <: Foo and a parameter f: Foo and returns Some(f: A) if f <: A, else None: trait Foo def cast[A <: Foo](...
0
votes
1answer
58 views

Are abstract type members a compile time construct?

Scala: Are abstract type members a compile time construct? Are they erased like type parameters?
0
votes
0answers
52 views

Form type, how to get the annotation error

Do you how I can get the annotation error from my entity to display them in my twig page ? My controller : class HomeController extends Controller { public function indexAction(Request $request) ...