jducoeur: (Default)
[personal profile] jducoeur
I'm starting to dig more seriously into Scala's Shapeless library, and it occurs to me that some of my more intrepid readers might find this interesting.

One of the most powerful and scary websites you will ever find in programming is typelevel.org. This is a collection of the most fascinating and brain-breaking libraries you will find out there today. AFAIK, they all derive at some level from the old observation that Scala's type system is sufficiently complex, it is actually Turing-complex unto itself. And that means you can do remarkable, powerful, slightly insane things with it.

The best-known of the bunch is scalaz (pronounced "ScalaZed", I gather). While it is oversimplifying to say that scalaz is Haskell implemented in Scala, I believe that's a decent first-order approximation.

There is Shapeless, linked above, which implements "polytypic" generic programming. The part that everyone gets swept up by is the HList data structure -- basically a meta-type which is a "list" of arbitrary other types, combining the best aspects of lists and tuples in a type-safe way -- but I gather that that is basically an implementation detail. The real goal is being able to abstract over algorithms at a higher-kinded level: for example, abstracting out the concept of "tree traversal" without needing to depend upon any specific implementation of "tree". (I think: Shapeless was the topic of the latest episode of The Scalawags, which inspired today's surfing.)

Those are the best-known parts of typelevel, but I find that there is a lot more there now. There is ScalaCheck, which lets you describe the "properties" of your methods, and then generates randomized data to hammer at those methods and make sure your invariants are actually invariant. There's scodec, a functional library for working with binary protocols. There is Spire, a numeric library that is designed to let you write efficient numeric code that works for any implementation of "number".

Etc -- the typelevel page itself is a bit thin, but provides pointers for what to look for online. I expect to spend a number of months wrapping my head around the more-interesting bits and pieces here...
(will be screened)
(will be screened if not validated)
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

Profile

jducoeur: (Default)
jducoeur

June 2025

S M T W T F S
12 34567
891011121314
15161718192021
22232425262728
2930     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags