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

Adding Interweaved Type and Term Clauses to function definitions #13836

Closed
wants to merge 11 commits into from

Conversation

Sporarum
Copy link
Contributor

@Sporarum Sporarum commented Oct 27, 2021

This is no longer up to date, pleaser refer to: #14019

This aims to add the ability to declare functions with many clauses of type parameters, instead of at most one, and to allow those clauses to be interweaved with term clauses, here's a motivating example you can find here:

trait Functor[F[_]]:
  def map[A](x: F[A])[B](f: A => B): F[B]


given Functor[List] with
  def map[A](x: List[A])[B](f: A => B): List[B] =
    x.map(f)

def assertTransformation[F[_]: Functor][A](original: F[A])[B](expected: F[B])(mapping: A => B): Unit =
  assert(expected == summon[Functor[F]].map(original)(mapping))

@main def test =
  assertTransformation(List("a", "b"))(List("a1", "b1")){elt => s"${elt}1"}

The delaying and currying of type parameters allows us to only explicitly use parameters that are harder/impossible to infer, for example:

The exact grammar and semantics can be found in this PR to the scala 2 docs

@soronpo
Copy link
Contributor

soronpo commented Nov 4, 2021

A few comments:

  • Should handle and test for extension definitions as well.
  • Should test of overriding and signature check and proper report when signature does not match.
  • I suggest opening a thread on https://contributors.scala-lang.org/ to discuss this language change.

@Sporarum Sporarum closed this Dec 1, 2021
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

Successfully merging this pull request may close these issues.

2 participants