b-studios

The UberFunctor: Higher Order Functors

This week I was faced with the problem of abstracting over two functors like F1[O] = Int × O and F2[I, O] = (I => Int) × (I => O). Both look very similar, but not similar enough – so I had to repeat the functor with the slight changes over and over again. Then I came up with a solution…

Scala: Implicit Optionals

A few days ago I stumbled apon Paul Phillips awesome talk “Inside the Sausage Factory” – explaining some internals of the Scala compiler. In his talk he mentions that he does not like using Option since it is “tedious and syntax heavy”. He suggests to use the “null object pattern” – creating a “distinguishable object to server the role of none”.

A problem with this approach is that one looses all the nice methods Option provides such as getOrElse or map. In this post we will see how we can get the best of both worlds by using implicits.

From Term to Typelevel

During this winter break I decided to jump into developing an alternative Scala wrapper for the Java Framework Vaadin. Many parts of the API are dealing with measurements like pixels or cm, so having a good design for handling measurements is crucial. In this post we first develop an API on the termlevel and then shift parts of the validation to the typelevel using a typeclass encoding.

Lazy Attributes in ECMAScript 5

Working on some project I noticed myself using the memoization pattern many times to create lazy evaluated properties. With ES5 a new way of implementing lazy attributes becomes available, preserving the interface of an attribute.

Using Scala Type Constraints

I didn’t think I will ever write about homework assignments, but this one was too cool. The task: “Write a wrapper class for collections, that reifies all operations on it.” In other words, queries on the collection should be available as AST in order to perform optimizations on them. This post is about one small problem related to the task.