Orthogonality1: Containers and functions, and the question of datatypes.

February 28, 2014

A pure function transforms data into other data statelessly

A container, such as an array or hash, stores data…statefully , but what you get back is what you put in … no transformation takes place.

These are orthogonal concepts. So far, so good. The problem is types. Functions need type systems because functional, as opposed to procedural, code is hard to debug.. if all the looping is implicit, you can’t insert debugs. Functional code therefore needs static type checking to catch errors at run time. Moreover, mathematical functions are a natural fit for mathematical type systems, such as the real and the rationals.

Onthe other hand, the power of dynamic languages comes from flexible data structures and no-fuss type systems. The fact that you don’t have to define a container for every base type speeds development, and having a mixture of value types in a container is not obviously a problem in the way that multiplying a string by a number is. And dynamic languages don’t need static type checking to catch errors, since , so long as they stick to the procedural model, errors can be caught with run-time debugging.

So there is a n orthogonality between dynamic and functional languages. Can we have the best of both?

One objection is that dynamic languages can’t have static systems because , being dynamic, they are not compiled. However, static-style type annotations checking only needs to occur before runtime, and to scan all the code before execution. This can be added as a front end to any dynamic language, and is a natural fit to those which have a initial stage of translation into bytecode.

In addition, there is a widespread assumption that if you have a static type system, then you have mandatory type annotations on everything. This assumption reflects common, de facto practice in language design, but is not matter of necessity., since a language could apply static type checking only where type annotations are supplied. However, this has some complications: In statefully typed compiled languages, the raw binary representation of a value can be stored straight into a container without loss of type information , since that is attached to the container. Adding dynamic types (essentially variant types or tagged unions) requires a different regime where runtime type information is boxed in with the value.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: