You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, Scala has no support for curried type signatures.
sealedtraitMyNumberclassMyDouble(d: Double) extendsMyNumberclassMyFloat(f: Float) extendsMyDouble(f.toDouble)
objectMyDouble {
defapply(d: Double):MyDouble=newMyDouble(d)
}
objectMyFloat {
defapply(f: Float):MyFloat=newMyFloat(f)
}
defconcatIterable[T, A<:T, B<:T](fst: Iterator[A])(snd: Iterator[B]):Iterator[T] = {
valfstLub:Iterator[T] = fst
valsndLub:Iterator[T] = snd
fstLub ++ sndLub
}
objectTest{
valfst=List(MyFloat(1f), MyFloat(2f), MyFloat(3f)).toIterator
valsnd=List(MyDouble(4d), MyDouble(5d), MyDouble(6d)).toIterator
valres= concatIterable(snd)(fst)
// Does not compile val res2 = concatIterable(fst)(snd)// Does not compile val res3 = concatIterable(fst)(_)// Does not compile res3(snd)
}
When I think about this, it seems to me that both T and B are unknown and cannot be inferred until it hits the call site. In the first does not compile, T is locked to MyFloat, and cannot be expanded later.
// Does not compile val res2 = concatIterable(fst)(snd)
// Does not compile val res3 = concatIterable(fst)(_)
// Does not compile res3(snd)
Actually, all of those compile fine in Dotty due to improved type parameter inference (we instantiate type parameters as late as possible, whereas scalac instantiate them after every list of argument). There might be a case for curried type parameters but it will need to be better motivated, especially considering the added complexity to the language.
Uh oh!
There was an error while loading. Please reload this page.
Currently, Scala has no support for curried type signatures.
When I think about this, it seems to me that both
T
andB
are unknown and cannot be inferred until it hits the call site. In the first does not compile,T
is locked toMyFloat
, and cannot be expanded later.Ideally, i'd like something like
The text was updated successfully, but these errors were encountered: