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

Add support for SAM conversion of polymorphic method #9916

Open
scabug opened this issue Sep 7, 2016 · 1 comment
Open

Add support for SAM conversion of polymorphic method #9916

scabug opened this issue Sep 7, 2016 · 1 comment

Comments

@scabug
Copy link

scabug commented Sep 7, 2016

As per spec this is not currently supported.
But javac support them just fine and they are quite useful. The following program return true in Java:

import java.util.function.Function;
import java.util.function.Supplier;

@FunctionalInterface
public interface Maybe<A> {

  <X> X fold(Supplier<X> empty, Function<A, X> just);

  static <A, X> X empty0(Supplier<X> empty, Function<A, X> just) {
    return empty.get();
  }

  static <A> Maybe<A> empty() {
      return Maybe::empty0;
  }

  static void main(String[] args) {
    Maybe<?> emptyString = Maybe.<String>empty();
    Maybe<?> emptyInt = Maybe.<Integer>empty();

    System.out.println(emptyString == emptyInt); // print "true".
  }
}

Fixing this issue would mean that the following code compile and print "true":

trait Maybe[A] {
  def fold[X](empty: => X, just: A => X): X
}

object Maybe {
  def empty0[A, X](empty: => X, just: A => X): X = empty

  def empty[A]: Maybe[A] = empty0(_ , _) // does not compile

  def main(args: Array[String]): Unit = {
    val emptyString: Maybe[String] = Maybe.empty
    val emptyInt: Maybe[Integer] = Maybe.empty

    print(emptyString eq emptyInt) // how to make this print "true"???
  }
}
@scabug
Copy link
Author

scabug commented Sep 7, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9916?orig=1
Reporter: Jean-Baptiste Giraudeau (jbgi)
Affected Versions: 2.12.0-RC1

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

1 participant