Magnolia is a new language intended for experimentation in programming language design, program transformation and optimisation. It is meant to be general-purpose, but is motivated by the numerical programming domain (in particular, coordinate-free numerics), where high performance and support for parallel architectures is critical. As part of the SAGA project, we have a numerical software library with a number of computationally intensive simulation applications, which is being ported to Magnolia.
Quick Feature Overview
- Concepts & Axioms
- Similar to what is proposed in the upcoming C++0x standard. Concepts are basically interface declarations for abstract data types, and allow you to constrain parameters of generic code. Axioms is an important and integrated part of development in Magnolia; they are used in domain engineering, as a basis for automated testing and for domain-specific optimisation.
- Axioms are statements about the operations in a program that should be true -- often used in program verification. In Magnolia, axioms can be used to derive rewrite rules to use for optimisation. For example, a matrix library may come with axioms that are used as algebraic simplification rules for matrices. Axioms are also used for systematic testing of programs. Furthermore, we are exploring the use of axioms to determine that components are interchangeable.
- Paper: Bagge, A. H. and Haveraaen, M. 2008. Axiom-Based Transformations: Optimisation and Testing. In Proceedings of the 8th Workshop on Language Description, Tools and Applications (LDTA ’08). Budapest, Hungary, April 5th, 2008. Electronic Notes in Theoretical Computer Science, Elsevier.
- Unified Algebraic Signature for both Imperative-style and Expression-style code
- A clear distinction is made between procedures (which may change their arguments) and functions (which are `pure', and may not change their arguments). Through the process of functionalisation, procedures are made available as pure functions. The pure function form is relates directly to the style found in specifications and axioms and is also close to the mathematic expression style underlying numerical programming.
- The inverse process of mutification is applied to the code, to turn function calls into procedure calls, which typically require fewer intermediate temporaries and copying of values.
- Certain operations -- like IO -- involving uncopyable objects may not be subjected to functionalisation/mutification. Programmers are encouraged to write their code as function calls as much as possible, since analysis and optimisation is easier to perform on pure functional expressions.
- Paper: Bagge, A. H., and Haveraaen, M. 2009. Interfacing Concepts: Why Declarations Style Shouldn’t Matter. In Proceedings of the 9th Workshop on Language Description, Tools and Applications (LDTA ’09). York, UK, March 28--29, 2009. Electronic Notes in Theoretical Computer Science, Elsevier.
- Alerts for Handling Errors and Partiality
- Alerts provide a unified interface to failure handling mechanisms like error return codes, global flags and exceptions. Alerts may also be used to add invariants to procedures and functions. Alert handling policies may be introduced either locally in an expression or procedure, or at the module or global level. Policies can specify substitution of default values, running of special handling code (e.g., to roll back partially completed operations), or propagation of the alert.
- Paper: Bagge, A. H., David, V., Haveraaen, M., and Kalleberg, K. T. 2006. Stayin' alert: moulding failure and exceptions to your needs. In Proceedings of the 5th international Conference on Generative Programming and Component Engineering (GPCE ’06). Portland, Oregon, USA, October 22–26, 2006. ACM, New York, NY, 265-274.
- Magnolia is syntactically similar to C/C++/Java, but a little more keyword-heavy. Generally, we try to make things look like C++ unless there is a good reason not to.
- Transformation and Macro System
- Magnolia has syntax macros and a built-in transformation system, to make it easy to extend the language with new features and to program library-specific optimisations.
- Dependent Typing
- Dependent Types let you embed more of the structural characteristics of objects in the type system. For example, the size of an array can be made part of its type, and compatibility of different arrays can be enforced by the type system.
- Static type checking can be used when enough information is available.
- Dynamic type checking code can be generated when sizes can only be determined at run time (when loading data from files, for example).
- Dependency-driven programming
- The DDA-based repeat construct is a new language feature to allow the explicit specification of 1) the underlying data-dependency pattern of a program and 2) the actual computation formalised in terms of this dependency. The background theory of Data Dependency Algebra (DDA) and its embedding onto the space-time communication layout of a hardware architecture shows how such specification can be spelled out as actual computations to be performed on different target machines. This allows the Magnolia compiler to generate code for specific hardware architectures. In particular this plays an important role when the target architecture is a parallel machine of some sort (MPI cluster, hypercube, GPU, many-core, etc.), since code targetting various machines can be generated from the same high-level abstraction.
- Paper: Burrows, E and Haveraaen, M. A hardware independent parallel programming model. Journal of Logic and Algebraic Programming, (to appear), 2009.
Bagge, A.H. The Magnolia Programming Language. Presentation at the PLDI 2008 Student Research Competition. Tucson, AZ, June 11, 2008. (Probably difficult to follow without the accompanying talk...)
Magnolia is early in its development (though many of the ideas have been researched already in a C++ setting). An early release is available below, with support for a few rudimentary language features (procedures, functions, functionalisation/mutification, ints and strings). The implementation consists of a frontend and an interpreter. A compiler producing C++ code is planned.