Created
March 17, 2017 13:12
-
-
Save CremboC/f5d6cf1442364f7268bb99798562cc49 to your computer and use it in GitHub Desktop.
This file contains 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
trait Parser[A, B] { | |
def parse(in: A): B | |
} | |
object Parser { | |
implicit val intToStringParser: Parser[Int, String] = | |
(in: Int) => { | |
in.toString | |
} | |
def apply[A, B](implicit parser: Parser[A, B]): Parser[A, B] = parser | |
} | |
// doesn't work | |
def parse[A, B](in: A): B = Parser[A, B].parse(in) | |
// works | |
def parse[A, B](in: A)(implicit parser: Parser[A, B]): B = Parser[A, B].parse(in) | |
parse[Int, String](10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment