Archive for August, 2011

Constructor Patterns

August 22, 2011

Currently (Babel-17 v0.3.2), how destructing works is not really what I intended initially:

def myobj = object def destruct_ Boom = 1 end

  match myobj
    case Boom x => false
    case Boom ! x => x == 1

 match Boom 1
   case Boom x => x == 1
   case Boom ! x => false

Both assertions currently hold. This is because the pattern Boom x only matches a true cexpr, but not a value that just responds to the destruct_ message.

The thing is that initially I introduced constructors just so that effortless pattern matching is possible against objects that are NOT of type cexpr, but choose to behave as such. Therefore the pattern C pat where C is a constructor should really mean the same as C ! pat. There is only one problem with that:

typedef suit Hearts, Diamonds, Spades, Clubs

This currently is short for

typedef suit (x as Hearts) = x
typedef suit (x as Diamonds) = x
typedef suit (x as Spades) = x
typedef suit (x as Clubs) = x

Now, if I do the following:

def myobj = object def destruct_ Hearts = nil def hello = "Hello there!" end
val strangeSuit = suit myobj 

Now strangeSuit is of type suit, but also responds to the hello message. That surely wasn’t intended.

The solution is to define the meaning of the suit type definition
to be:

typedef suit Hearts = Hearts
typedef suit Diamonds = Diamonds
typedef suit Spades = Spades
typedef suit Clubs = Clubs

Then everything works fine and the encapsulation of the suit type is guaranteed.


Programming and Scaling

August 7, 2011

Interesting talk by Alan Kay, the inventor of the term “object-oriented”: Programming and Scaling.

Midnight in Paris

August 6, 2011

I don’t understand, what’s holding them in the room?

You gotta love Woody Allen’s newest creation, for little fun moments like above reference to “The Exterminating Angel”, and for pointing out obvious, but easily forgotten truths. If you haven’t already, it will also make you fall in love with Paris. Makes me want to jump right into the train from Saarbr├╝cken to Paris.