Bla Language


modified: 2013/08/2

(A language & compiler I worked on for my Masters in '95:)

Available material

The paper on Bla: pdf, ps or dvi format, layout for `letter' papersize (about 66 pages). Versions on A4 (40 pages) are available (pdf, ps or dvi). If all this doesn't suit your output medium, then you can have a go at it yourself using the LaTeX2e source. If all else fails, download the dokkenou source which is very well readably as ascii.

If you're very interested, you can download a very early beta of the Bla compiler implementation here. You'll need a modern Unix with a recent GNU C++ or an Amiga to use it.

The Bla Language: Extending Functional Programming with First Class Environments

abstract: We investigate an (unpure) functional language whose concept of environment is not implicit as in traditional languages, but made available explicitly as a first class value. This results in a semantics for environments that is best known from the object oriented paradigm, and gives us a united function/class concept in a very orthogonal way. We also look at the language as a real-world general purpose language, considering semantics (of type-inference, for example), implementation issues, and practical experience in using the compiler.

The BuzzWord Introduction:

  • Environments as First-Class values.
  • Inclusion and Parametric polymorphism (i.e. Late Binding and Genericity), Type-Inference (Hindley Milner variant), Compile-Time Type-Safety (ContraVariance).
  • Multiple Inheritance and Subtyping.
  • Higher Order functions (Function Closures), Lambda's.
  • Black-Box Safe (though flexible) Per-Module DataHiding (Encapsulation).
  • Extensive Pattern Matching facilities, General Equational Syntax.
  • Builtins Types like Lists and Vectors.
  • Tagged Arguments.
  • Exception Handling.

A tiny introduction to some important concepts:

This text tries to give the reader a general feel what Bla is about, starting with core concepts. Familiarity with functional / object oriented languages and associated concepts is assumed.

The core of Bla is basically a functional language. A key feature of most functional languages is the concept of a _higher order function:_ the ability of functions to receive as argument or return other functions. To do this succesfully in the case of returning a function, it must be possible to keep the environment of the higher order function around, even if the function terminated long ago, since free variables in the returned function might need that environment. Functional programmers have exploited this feature by using the environment of enclosing functions as “objects”.

A slight problem with using these environments as objects is that only one function has access to it: the object is anonymously captured “in” the function. The change that Bla makes to this model is very simple, but has great consequences: _it makes the environment object explicitly available as value._

In Bla, every function has available the value `self' which denotes that function's environment object. One of the most simple things that can be done with this value is return it: the caller of that function then receives an object. So a function definition of function `f' introduces not only a new function, but also a type `f', being the type of its environment object. A call to `f()' creates an object of type `f' and executes the code of the function within that environment.

functions local to other functions are actually functions that are required to be evaluated within the environment of a certain function. Since this environment is now accessable as object, local functions can be invoked wherever such an object is around as value: they obtain the same role and semantics as methods in OO languages. Other object oriented features come (almost) for free as well.

Using this concept of “1st class environments”, Bla integrates functional and object orientedness in a tiny language, in an elegant and natural way. However, on top of this core language, Bla adds quite a few concepts to make programming practical.

The type system used by Bla is a variation on the Hindley-Milner system, and provides very practical parametric polymorhism (extensions mostly to support OO constructs, providing inclusion polymorhism). The compiler uses a powerful type-inferencer and Bla is compile-time type-safe.

Bla breaks with referential transparency and allows use of assignment as well.

some sample sourcecode:

map(f,[])    = []
map(f,[h|t]) = [f(h)|map(f,t)]

qsort([],_)     = []
qsort([h|t],lt) = append(qsort(filter(lambda(x) = lt(x,h),t)),
                  [h|qsort(filter(lambda(x) = not lt(x,h),t))])

stack()[T] = self where
  d = []
  isempty() = d=[]
  push(x:T) do d:=[x|d]
  pop():T = d <=> []    -> raise stack_empty
          | d <=> [h|t] -> h do d:=t

If you want more than toy-examples, have a look at this prolog interpreter written in Bla