Skip to content
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

relax ordering restriction on dependent method types #4718

Open
scabug opened this issue Jun 20, 2011 · 4 comments
Open

relax ordering restriction on dependent method types #4718

scabug opened this issue Jun 20, 2011 · 4 comments

Comments

@scabug
Copy link

scabug commented Jun 20, 2011

motivational examples from test/files/pos/depmet_implicit_oopsla_session_2.scala and neg/depmet_try_implicit.scala

def runSession[S, D](p: S, dp: D)(implicit s: Session[S]#HasDual[D]) =
  s.run(p, dp)

def runSession[S, D](p: S, dp: D)(implicit s: Session[S]{type Dual=D}) =
  s.run(p, dp)

can we relax the ordering restrictions on dependencies so that we can write

def runSession[S](p: S, dp: s.Dual)(implicit s: Session[S]) =
  s.run(p, dp)

this is more than an encoding of the first two snippets as it hides the inference of D, so that you can specify S, but not D (unless you supply the implicit argument explicitly)

(Conceptually, it would be even nicer to be able to write the following, emphasizing the similarity between implicit arguments and type parameters)

def runSession[S][val s: Session[S]](p: S, dp: s.Dual) =
  s.run(p, dp)

It could work by re-arranging argument lists behind the scenes, possibly splitting up the
implicit argument list, so that the current left-to-right ordering requirement is upheld: types can only depend on arguments on their left.

This is related to the multiple type parameter lists generalisation:

  def foo[A1, A2][B1, B2](p1 : (A1, B1)) : (A2, B2) = ...

could be rewritten to:

  def foo[A1, A2](p1 : (A1, w.B1))(implicit w: FooBs[A1, A2]) : (A2, w.B2) = ...
@scabug
Copy link
Author

scabug commented Jun 20, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4718?orig=1
Reporter: @adriaanm

@scabug scabug added this to the Backlog milestone Apr 7, 2017
@scala scala deleted a comment from scabug Jan 15, 2024
@SethTisue
Copy link
Member

(for aid in searching) the error message in Scala 2 is:

error: illegal dependent method type: parameter may only be referenced in a subsequent parameter section

I don't think Scala 3 has anything that facilitates this, but please correct me if I'm wrong.

@joroKr21
Copy link
Member

I don't think Scala 3 has anything that facilitates this, but please correct me if I'm wrong.

In Scala 3 you could write this:

def runSession[S](p: S)(using s: Session[S])(dp: s.Dual) =
  s.run(p, dp)

@SethTisue
Copy link
Member

Oh, nice! Funny, I thought I had tried it, must have done it wrong.

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

No branches or pull requests

3 participants