Justin du Coeur (jducoeur) wrote,
Justin du Coeur
jducoeur

Scala Circuitries

I burble about Scala on a regular basis, and part of that is because I really like the growing snowball effect. Since Scala is the Cool Language, it's where the largest number of cool theoreticians are gathering, to come up with more ideas about how to make the language cooler, feeding in a virtuous spiral. It's a delicate dance, but so far it's managing to remain solidly practical and pragmatic while still evolving an order of magnitude faster than something like Java.

Historically, its evolution has mostly consisted of applying the best practices and ideas found elsewhere in the programming world, combining them into a single coherent framework. But now, it's starting to be where the cutting-edge ideas *start*.

Today's example is Scala Circuitries. WARNING: this is really, really deep stuff -- I can barely hang on by my fingernails through this slide deck, and I don't recommend it to anyone except very experienced programmers with at least a little background in modern CS theory.

That said, the ideas here are breathtaking. It uses Scala as the example language to tease out a generalized concept of Circuitries, arguing that they are the better generalization that ideas like Monads, Applicatives and Arrows are stepping-stones towards. They describe a general conceptual framework for thinking about programs with side-effects -- and more importantly, start teasing out some nicely general concepts of how those side-effects combine.

The payoff is in the last 20 slides, where they start hinting at some very advanced but likely achievable ways in which you could start to program in ways that look conventional, even procedural, but capture the side-effects of those programs automatically. They're nowhere near there yet, but this is holy-grail stuff: if you can take arbitrary programs, reduce out all of the side-effects in predictable ways and leave pure functional code, it can advance the art of programming by leaps and bounds. (Not least, in that it potentially leads to being able to automatically parallelize arbitrary code, which would be a *huge* advance.)

Note that you may need to take a dig into the brand-new Scala Macro system to really understand what's going on here. The Macro system is itself a great example of how the language is evolving: it's a very formal meta-programming environment that allows you to write higher levels *in* Scala, that get executed at compile time. The term "macro" is controversial -- a lot of people feel that C++ has polluted the word forever -- so some folks refer to them as CATs (which I believe stands for Compile-time AST Transformers). Basically, they look almost like functions, but instead of being executed at runtime, they instead get fed the Abstract Syntax Trees of their parameters at compile time, and have reasonably clean mechanisms for transforming and emitting those trees. (In technical terms, they aren't quite hygenic in the traditional sense, but the design makes a good argument that they come close enough if you follow some specific practices.)

It's worth saying clearly: we are in an absolute golden age for programming right now. It's scary as hell -- I'm good at this, and still often have trouble keeping up with how fast the cutting edge is advancing. But stuff like this is a large part of why I stay so engaged in my field: it's just incredible *fun* watching things evolve right before my eyes...
Tags: programming, scala
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 1 comment