运行-副产品的时间成本?

Run-time Cost of Coproduct?

看完Solving Problems in a Generic Way using Shapeless第一句结论:

In this article, I've demonstrated how generic solutions can be created for ADTs without relying on an expensive runtime feature such as reflection

这是否意味着 Shapeless 的副产品 使用 运行 时间反射或转换,这与 Scala 中的 ADTs 相反?

我是博客 post 的作者。我认为存在一个误解:我并不是要暗示 ADT 依赖于运行时反射。我指的是介绍中的这句话:

Traditionally, generic programs have been written with the help of reflection APIs.

据我所知,ADT 不使用运行时反射,但如果没有 shapeless,以通用方式遍历 ADT 的选择并不多。实现此目的的一种方法是对 looking up object fields at runtime 使用反射并遍历字段。您还可以编写遍历 ADT 的代码并在每个 ADT 节点上进行模式匹配,但该解决方案仅适用于您的 ADT 而不适用于所有其他 ADT,即解决方案不是通用的。