score:1
If you can relax the requirement that XDependent
has to be a trait
, and make it an abstract class
instead, then it seems as if a typeclass which provides a single null-ary method x
is exactly what you want:
Here is your base trait X
(without X.x
or anything, that wouldn't be "static"):
trait X
Now you can define a typeclass HasStaticX[T]
that guarantees that for a type T
we can give some string x
:
trait HasStaticX[T] {
def x: String
}
Then you can use it like this:
abstract class XDependent[T <: X : HasStaticX] {
def printX: String = implicitly[HasStaticX[T]].x
}
What HasStaticX
does is essentially building a compile-time partial function that can take type T
and produce a string-value x
associated with T
. So, in a way, it's something like a function that takes types and returns values. If this is what you want, then nothing has to be done to for "integrating static values", it just works in the current non-experimental mainstream versions of Scala.
The "value-dependent types" would be exactly the other way round: those would be essentially "functions" that assign types to values.
Source: stackoverflow.com
Related Query
- Static Values in Traits Shared by Objects that Extend It
- Scala: What is the difference between Traversable and Iterable traits in Scala collections?
- Map both keys and values of a Scala Map
- What are the differences and similarties between Scala traits vs. Java 8 interfaces?
- Traits and abstract methods override in Scala
- Mixing multiple traits in Scala
- Using Scala traits with implemented methods in Java
- Why doesn't Scala have static members inside a class?
- How are Scala traits compiled into Java bytecode?
- Are there any tools for performing static analysis of Scala code?
- Static return type of Scala macros
- Static inner classes in scala
- Formatting binary values in Scala
- Scala client composition with Traits vs implementing an abstract class
- Scala 2.10 reflection, how do I extract the field values from a case class, i.e. field list from case class
- What is Scala equivalent of Java's static block?
- Scala trait - Is there an equivalent of Java interface public static field?
- Does Scala have static imports like Java?
- How do I access default parameter values via Scala reflection?
- Substitute values in a string with placeholders in Scala
- Getting autoincrement values with Slick library in Scala
- Defining implicit view-bounds on Scala traits
- Does Scala have a library method to wrap nullable return values in an Option?
- Semantics of abstract traits in Scala
- Scala case classes with Mixin traits
- Getting values from Map given list of keys in Scala
- How does Scala maintains the values of variable when the closure was defined?
- Read values from config in Scala
- Scala lazy values : performance penalty? Threadsafe?
- Why == operator and equals() behave differently for values of AnyVal in Scala
More Query from same tag
- How to define a recursive algebra for use in free applicative?
- equivalent to the javascript operator || in scala
- How to set CHARACTER SET for writing to MySQL table using JDBC data source?
- Scala Array manipulation task which requires two pointers [Scala]
- how to convert current_timestamp() value in to a string in scala
- Naming fields in immutable functional objects
- MongoDB Scala Driver doesn't allow use Map collection in case class
- Fetch all entities from case class and convert them to string
- SBT not running from root directory
- How to select a object field for map value in Scala using groupby
- Plotly and IntelliJ IDEA
- Inverse a nested Map in Scala
- slick error : type TupleXX is not a member of package scala (XX > 22)
- Dataframe in Spark is getting returning "d1: Unit = ()" after datediff transformation is applied
- Using function to update case class value in scala Quill
- Is it possible to use Eclipse IDE and GAE plugin to develop and deploy Scala Applications with PlayFramework?
- How to serialize scala BKTree?
- Maven - webstart could not be activated
- Extract data from a Spark RDD, and populate a tuple in scala
- Scala mixin with object
- Difference between scalaSource and sourceDirectories in sbt
- Force scala.Predef initialization on application start without affecting the code
- Scala: Button in Table Cell does not "fire" Action
- Replace a method for usage only in a particular unit tests in Scala
- type-case in a type synonym
- Apache Spark: how to cancel job in code and kill running tasks?
- how to return value from a if block in scala
- How to create a dynamic expression in the filter?
- What is the Scala equivalent of the `this` operator in Java?
- Scala: How to create a Map[K,V] from a Set[K] and a function from K to V?