Created
November 8, 2016 16:34
-
-
Save utaal/fa3de004f418bc01adf3a72ab69bf0bd to your computer and use it in GitHub Desktop.
https://twitter.com/travisbrown/status/795992815201304577 -inspired typeclass instance naming
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
case class Circle(radius: Double) | |
trait HasArea[A] { | |
def area(a: A): Double | |
} | |
implicit val `HasArea for Circle` = new HasArea[Circle] { | |
def area(circle: Circle): Double = Math.PI * Math.pow(circle.radius, 2) | |
} | |
println(implicitly[HasArea[Circle]].area(Circle(2))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment