Created
April 24, 2015 11:54
-
-
Save ubourdon/7da13188fa83df4d41d8 to your computer and use it in GitHub Desktop.
polymorphic function & type alias - compilation error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package object example { | |
| type ElasticSearchIndexation[X] = X => Future[Try[String]] | |
| type DatabaseInsertion[Z] = Z => Future[Option[Z]] | |
| def saveAndIndex[A](g: A => Future[Try[String]])(f: A => Future[Option[A]])(x: A): OptionT[Future, Try[String]] = ??? | |
| def saveAndIndexAlias[A](g: ElasticSearchIndexation[A])(f: DatabaseInsertion[A])(x: A): OptionT[Future, Try[String]] = ??? | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object Test { | |
| val toto: Toto = ??? | |
| val indexTotoInES: Toto => Future[Try[String]] = ??? | |
| val insertToto: Toto => Future[Option[Toto]] = ??? | |
| toto |> saveAndIndex(indexTotoInES)(insertToto) // compile OK | |
| toto |> saveAndIndexAlias(indexTotoInES)(insertToto) // Don't compile with errors : | |
| /** | |
| * type mismatch; | |
| [error] found : Toto => scala.concurrent.Future[scala.util.Try[String]] | |
| [error] required: example.ElasticSearchIndexation[A] | |
| [error] (which expands to) A => scala.concurrent.Future[scala.util.Try[String]] | |
| [error] toto |> saveAndIndexAlias(indexTotoInES)(insertToto) | |
| * | |
| ** / | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
out of curiosity does
toto |> saveAndIndexAlias[Toto](indexTotoInES)(insertToto)compile ?