Questions tagged [dependent-method-type]
11 questions
129
votes
4 answers
What are some compelling use cases for dependent method types?
Dependent method types, which used to be an experimental feature before, has now been enabled by default in the trunk, and apparently this seems to have created some excitement in the Scala community.
At first look, it's not immediately obvious…
missingfaktor
- 86,952
- 56
- 271
- 360
13
votes
2 answers
Path-dependent types and nested traits
Background
Suppose I have some nested traits:
trait Foo { trait Bar }
And a couple of instances:
val myFoo = new Foo {}
val myBar = new myFoo.Bar {}
I can write the following, which look (at least at a glance) like they should do more or less the…
Travis Brown
- 135,682
- 12
- 352
- 654
12
votes
1 answer
Dependent method types conflict with default arguments
When playing with scala's dependent method types, I encountered a conflict with default method parameters:
abstract class X {
type Y
case class YY(y: Y)
}
object XX extends X {
type Y = String
}
trait SomeTrait {
def method(x: X)(y: x.YY,…
Alexander Bulaev
- 245
- 1
- 8
8
votes
1 answer
Dependent method types and type-classes
I've got a bunch of data store type-classes that look all the same.
trait FooStore[C] {
def create(f: FooId => Foo)(c: C): Foo
// update and find methods
}
I'd like to simplify things and was hoping to use dependent method types to get…
purefn
- 826
- 4
- 14
5
votes
1 answer
Exposing a path-dependent type coming from a singleton type
I'm trying to make Scala find the right type for a path-dependent type coming from a singleton type.
First, here is the type container for the example, and one instance:
trait Container {
type X
def get(): X
}
val container = new Container {
…
betehess
- 817
- 4
- 18
3
votes
1 answer
Abstracting Case Classes
I'm exploring ways to abstract Case Classes in Scala. For example, here is an attempt for Either[Int, String] (using Scala 2.10.0-M1 and -Yvirtpatmat):
trait ApplyAndUnApply[T, R] extends Function1[T, R] {
def unapply(r: R): Option[T]
}
trait…
betehess
- 817
- 4
- 18
3
votes
1 answer
Pattern matching for abstracted case classes
I'm trying to abstract case classes in a module using dependent method types and a nightly build of the compiler (2.10.0.r26005-b20111114020239). I found some inspiration from Miles Sabin' example.
I don't really understand what's wrong in the…
betehess
- 817
- 4
- 18
2
votes
3 answers
Type equivalence issue when using dependent method types and the type projections
I'm trying the following with Scala 2.10.0-M1:
trait Container {
type X
}
class Test[C <: Container](val c: C) {
def foo(x: c.X): C#X = x // this compiles fine
def bar(x: C#X): c.X = x // this does not compile
}
The problem is the same when…
betehess
- 817
- 4
- 18
2
votes
1 answer
IntelliJ shows type mismatch errors about dependent method types, even though sbt compiles fine (scala)
I have a trait like following:
trait NumberRepository[C <: AppContext] {
def findAll(implicit ctx: C): ctx.Result[Seq[Int]]
def findEvens(implicit ctx: C): ctx.Result[Seq[Int]] = findAll.map(_.filter(_ % 2 == 0))
}
It can be compiled without…
xfan
- 35
- 4
1
vote
1 answer
How to construct a MethodType for a method with variant parameters
I failed to create a MethodType for a method lookup in Java. Below is my code. In this code, I want to create a MethodType for the sample::gwd method, and then retrieval reference to this function by lookup().findStatic. It is clearly that i can not…
shijie xu
- 1,861
- 17
- 42
1
vote
1 answer
Problems with Dependent Method Type
Consider the following code: Why is S.|.NotOrNot.OUT not equal to S.Not?
sealed trait S
object S {
trait Not extends S
trait A extends S
trait B extends S
trait C extends S
trait |[X <: S, Y <: S] { type OUT <: S }
trait…
Peter Schmitz
- 5,734
- 4
- 24
- 48