score:7
Accepted answer
This is what DummyImplicit
is for:
trait AbstractTypes {
type ScalarT
type VectorT
abstract class Operators(u: VectorT) {
def *(f: ScalarT): VectorT
def *(v: VectorT)(implicit dummy1: DummyImplicit): VectorT
}
}
You can have any number of DummyImplicit
s if you need more overloads whose erasure are the same.
score:0
Using one of the tricks from answer to the linked question (declaring parameter of the seconds method as call-by-name):
trait AbstractTypes {
type ScalarT
type VectorT
abstract class Operators(u: VectorT) {
def *(f: ScalarT): VectorT
def *(v: => VectorT): VectorT
}
}
object ConcreteTypes extends AbstractTypes {
type ScalarT = Double
type VectorT = Seq[Double]
class ConcreteOperators(u: Seq[Double]) extends Operators(u) {
def *(f: Double): Seq[Double] = u.map(_ * f)
def *(v: => Seq[Double]): Seq[Double] =
(u zip v).map { case (a, b) => a * b }
}
}
new ConcreteTypes.ConcreteOperators(Seq(2.0, 3.0, 5.0)) * 7.0
Seq[Double] = List(14.0, 21.0, 35.0)
new ConcreteTypes.ConcreteOperators(Seq(2.0, 3.0, 5.0)) * Seq(1.0, 2.0, 3.0)
Seq[Double] = List(2.0, 6.0, 15.0)
Source: stackoverflow.com
Related Query
- In Scala all abstract types have the same type after erasure
- Same type after erasure in opaque types in Scala 3
- Scala double definition (2 methods have the same type erasure)
- Why does Scala choose to have the types after the variable names?
- "MyType" problem: Do I have to use abstract types (or generics) in Scala to return the actual class?
- Why is the type of "Banana with Cream" the same as "Banana" after erasure ? How can it be fixed?
- Why do these functions have the same type after erasure?
- Is there a way to expand the scope of an existential type quantifier in Scala to convince the type checker that two variables have the same type?
- In scala 2, can macro or any language feature be used to rewrite the abstract type reification mechanism in all subclasses? How about scala 3?
- Scala work-around for methods with same type after erasure
- Why doesn't Scala infer type parameters the same way in my abstract class?
- Get reified type of symbol after the erasure phase of the Scala 2.9.3 compiler
- What special rules does the scala compiler have for the unit type within the type system
- Abstract Types / Type Parameters in Scala
- What is Scala way of finding whether all the elements of an Array has same length?
- What is the Scala type mapping for all Spark SQL DataType
- Why does Scala warn about type erasure in the first case but not the second?
- Mixing type parameters and abstract types in scala
- Scala Puzzle: enforcing that two function arguments are of the same type AND both are a subtype of a given class
- scala: how to create a generic type which is subtype of all the number classes in scala so that it can include compare method
- Returning the same type from abstract trait method
- Scala parameterized type problem with returning an instance of the same type
- How to ask for the same type in Scala generics without introducing a third type parameter?
- Scala type erasure issue with path dependent/nested types
- Why can method parameter F have the same name as type constructor F?
- avoid executing the same method in all scala actions in play framework
- Abstract and Final class defined on the same Scala Class
- Scala 2.10 reflection: Why do I get the same type "List()" for the list and list element?
- Question on the initialization of abstract type class in scala
- Scala val and type at the same time
More Query from same tag
- get the value of scala Some(text)
- Call by name parameters in scala functions
- How does scala's actor model make use of C threads and native system threads?
- scala - is it possible to force immutability on an object?
- How can one set a value for all subprojects in sbt shell?
- Scala reference to 'tupled' generically from case class
- How to rollback a migration in Flyway Scala?
- Using Scala extension of immutable class in Java
- Spark - How to parse a JSON-escaped String field as a JSON Object in DataFrames?
- Spark parse and processing file parquet/json
- How to build a path with a base path and relative path?
- Deal with foreign keys
- Spark scala use spark-mongo connector to upsert
- What should max() return for empty lists?
- How do I determine the optimal number of threads in Spark application?
- com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'play'
- Scala Tuples, Manipulating Map Data
- How to format and output table and constant data in a Scala Dateframe as JSON objects
- error trying to get errors with scala Try function
- Scala - how to set data into placeholder from config file?
- Test the message returned by an akka actor containing a Try[T]
- Is it possible to implement flip in Scala like it is implemented in Haskell?
- What does inlined mean?
- transform JavapairRDD to dataframe using scala
- scala filter a list based on the values of another list
- How to replace string values in one column with actual column values from other columns in the same dataframe? Part 2
- scala nested for/yield generator to extract substring
- Akka Streams: File Sink does not write stream elements
- Having 1 Slick table class per file and definition of foreign key
- How to configure hello-slick-3.0 app for mysql (async)