Skip to content

SAM doesn't work with polymorphic functions #6904

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

Open
guyde2011 opened this issue Jul 22, 2019 · 0 comments
Open

SAM doesn't work with polymorphic functions #6904

guyde2011 opened this issue Jul 22, 2019 · 0 comments

Comments

@guyde2011
Copy link

minimized code

trait List2Option{
  def apply[A](list: List[A]): Option[A]
}

val l2o: List2Option = [A] => (lst: List[A]) => lst.headOption

This code does not compile, with the error message
Found: Object with PolyFunction {...}
Required: List2Option

expectation

Would expect the compiler to accept it as a SAM implementation of List2Option, the same way it does with other irregular function types (as it does with dependant functions for example).

I will add that the following (quite unsuprisingly) does work, but this way forces you to use a pair of brackets on the apply method in List2Option

trait List2Option{
  def apply(): [A] => List[A] => Option[A]
}

val l2o: List2Option = () => [A] => (lst: List[A]) => lst.headOption
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

4 participants