Merry Christmas

The Full Algebra

A couple of posts ago I included a link to an explanation of Algebraic Types to explain the 'Product' in product types. If you read that (and I do encourage you to at least skim it), you should be wondering if Toccata has Sum Types as well.

It does.

(def Sequence (comp List
                    Vector))

A sum type like Sequence here, can only be used in assert and assert-result expressions. If the compiler can not prove a value is one of the types included in the sum, it will insert code at the appropriate place to check that at run time. But there's no possibility to 'pre-dispatch' a protocol function at compile time on the basis of a sum type. So they're mostly for bug catching.

The combination of Product and Sum types gives Toccata Algebraic Data Types. Or at least most of the functionality of ADT's. The goal Toccata's type system is not go all the way in the direction of Haskell or Scala. But to give as many of the benefits of a sophisticated type system to programmers who prefer dynamic types while imposing as little cost as possible. And there's quite a lot more benefit to be derived from the infrastructure that's been implemented so far. I hope add those features soon.

And since it's Christmas, we'll leave it at that.