Continuing yesterday's discussion of the shapeless library -- programmers who want to have their minds blown (or at least expanded) should take a look at the overview of shapeless 2.0. It goes *way* beyond the parts I mentioned yesterday, with concepts including:
- Truly polymorphic functions: a way to build functions that operate cleanly on multiple arbitrary Types. (Which is normally impossible in Scala.)
- The ability to use all of the usual List-like operations (head, tail, concatenation, etc) on tuples.
- HMap: a variant of Map that allows you to have keys of multiple types.
- Singleton Types: that is, "the Type that is the Integer 23", "the Type that is the string 'foo'", and so on.
- Extensible Records: sort of a hybrid between a compile-time class and a runtime Map -- heterogeneous and extensible, yet strongly-typed.
- Discriminated Unions (yay! One of the most-asked-for features in Scala).
- Lenses: strongly-typed "views" of a subset of the fields of a Type (including arbitrary fields of nested Types inside classes).
- Literal collections whose sizes are encoded in the type system, so that you can check that they match at compile time.
(Mind, I gather all of this can be done in Haskell as well -- it's just remarkable to see it in a language I actually use. It's a fine demonstration that, when used really well, Scala can be far more strongly-typed than something like Java or C#, for equivalent problems.)
Of course, the downside is that I'm starting to realize lots of places where I should be using this stuff in Querki. Adopting shapeless properly is going to be a long-term project...