return-current-type

Advantages of F-bounded polymorphism over typeclass for return-current-type problem

て烟熏妆下的殇ゞ 提交于 2020-03-13 13:39:45
问题 Returning the current type questions are often asked on StackOverflow. Here is one such example. The usual answers seem to be either F-bounded polymorphism or typeclass pattern solution. Odersky suggests in Is F-bound polymorphism useful? F-bounds do indeed add significant complexity. I would love to be able to get rid of them, and replace them with higher-kinded subtyping whilst tpolecat (the author of linked post) suggests A better strategy is to use a typeclass, which solves the problem

Advantages of F-bounded polymorphism over typeclass for return-current-type problem

喜夏-厌秋 提交于 2020-03-13 13:39:30
问题 Returning the current type questions are often asked on StackOverflow. Here is one such example. The usual answers seem to be either F-bounded polymorphism or typeclass pattern solution. Odersky suggests in Is F-bound polymorphism useful? F-bounds do indeed add significant complexity. I would love to be able to get rid of them, and replace them with higher-kinded subtyping whilst tpolecat (the author of linked post) suggests A better strategy is to use a typeclass, which solves the problem

Return copy of case class from generic function without runtime cast

落花浮王杯 提交于 2020-02-26 18:24:32
问题 I want to get rid of a runtime cast to a generic ( asInstanceOf[A] ) without implicit conversions. This happens when I have a fairly clean data model consisting of case classes with a common trait and want to implement a generic algorithm on it. As an example the resulting algorithm should take a class of type A that is a subclass of the trait T and is supposed to return a copy of the concrete class A with some updated field. This is easy to achieve when I can simply add an abstract copy