Skip to content

Support for curried type parameters #4110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DhashS opened this issue Mar 13, 2018 · 2 comments
Closed

Support for curried type parameters #4110

DhashS opened this issue Mar 13, 2018 · 2 comments

Comments

@DhashS
Copy link

DhashS commented Mar 13, 2018

Currently, Scala has no support for curried type signatures.

sealed trait MyNumber
class MyDouble(d: Double) extends MyNumber

class MyFloat(f: Float) extends MyDouble(f.toDouble)

object MyDouble {
  def apply(d: Double): MyDouble = new MyDouble(d)
}

object MyFloat {
  def apply(f: Float): MyFloat = new MyFloat(f)
}



def concatIterable[T, A <: T, B <: T](fst: Iterator[A])(snd: Iterator[B]): Iterator[T] = {
  val fstLub: Iterator[T] = fst
  val sndLub: Iterator[T] = snd
  fstLub ++ sndLub
}

object Test{
  val fst = List(MyFloat(1f), MyFloat(2f), MyFloat(3f)).toIterator
  val snd = List(MyDouble(4d), MyDouble(5d), MyDouble(6d)).toIterator
  val res = 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.

Ideally, i'd like something like

def typeCurriedConcatIterable[T, A <: T](fst: Iterator[A])[B <: T](snd: Iterator[B]): Iterator[T]
@DhashS
Copy link
Author

DhashS commented Mar 13, 2018

See #2576 for my hacky current workaround solution that does not support implicit parameter lists

@smarter
Copy link
Member

smarter commented Mar 13, 2018

// 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants