scala typeclass
-
sealed trait typeclassscala/basic 2022. 3. 29. 14:45
문제 sealed trait 대상으로 typeclass 를 정의할 때, 다음과 같은 문제가 있다. https://www.reddit.com/r/scala/comments/96woxd/how_to_implement_an_adt_that_all_members_have/ 코드 http://eed3si9n.com/herding-cats/typeclasses-102.html 참고 trait Eq[A] { def eqv(x: A, y: A): Boolean } object Eq { def apply[A](implicit eq: Eq[A]): Eq[A] = eq implicit class EqSyntax[A](x: A) { def ===(y: A)(implicit eq: Eq[A]): Boolean = eq.eqv(..
-
typeclass 는 언제 사용하면 좋을까?scala/basic 2021. 6. 9. 10:44
https://w.pitula.me/2017/typeclasses-vs-polymorphism/ Typeclass: when inheritance is not enough If you ask Wikipedia about polymorphism, it will tell you that it is about “provisioning a single interface to entities of different types”. And this is true(remember that interface here and in whole post means API, not some element that is part of the w.pitula.me 1. 기존 class 에 새로운 method 를 추가할 때 2. 동..