3 ms·
This is a really awesome post for demystifying typeclasses -- which are incredibly useful -- as well as some of the really basic stuff you can do with Shapeless
by acjohnson55 11y ago
This is a really awesome post for demystifying typeclasses -- which are incredibly useful -- as well as some of the really basic stuff you can do with Shapeless-style type-level programming. The play-json library is how I first started messing with this stuff, but the circe library the author wrote seems to take this to another level. The latter not only seems conceptually and functionally simpler, but is more powerful, given its direct support for sealed trait hierarchies, a core feature of Scala. And it seems to do so in a pretty intuitive way, representing a subtype as a JSON object with the subtype name as the key and a subobject as the value set, as opposed to synthesizing a `type` field of some sort to disambiguate the cases.
My biggest complaint is with some of Scala's ergonomics for working on the type level. I'd argue that built-in tuples should simply support the HList operations natively, which seems like it could save on a whole lot of complex looking type-level code. I'm right with the author until `hconsParser` and especially `caseClassParser` started bending my brain. But I guess the good news is that those only need to be written once.