The Holy Grail of programming language design is to create a simple yet powerful language with a small number of orthogonal building blocks that can be composed together in many ways.
Design Strategies for Composability:
- declarative semantics
- orthogonality
- unify features that are almost the same, but with unnecessary differences
- split up features that do two things at once into separate features that can be composed
- eliminate the need to write "glue" code when composing elements, by using standard interfaces
- remove restrictions on how language elements can be composed
- eliminate syntactic overhead for common compositions
Composability Failure in OpenSCAD:
- Can't pass a function as an argument to a module for generalized extrusion. Fix: First Class Values.
- Can't compose
for
withintersection
. Fix: this is the module composability problem. concat
has a variable-length argument list, and can't be composed with an expression that generates a sequence of lists to be concatenated, eg afor
loop, so users implementflatten
instead. In Haskell,concat
takes a single argument, which is a list of lists: this makes Haskell'sconcat
highly composable, and eliminates the need for a separateflatten
function.- Can't compose
children()
withfor
, egfor (shape=children()) ...
. Fix: Generic Sequences. - Ranges can be composed with
for
, but can't be interchanged with lists of number in other contexts. Fix: Generic Sequences.