Paradigm(s) imperative, structured, modular
Appeared in 1980s
Designed by DEC and Olivetti
Developer elego Software Solutions GmbH
Stable release 5.8.6 (July 14, 2010)
Preview release 5.8.6 (July 14, 2010)
Typing discipline strong, static, safe or if unsafe explicitly safe isolated
Major implementations CM3, PM3, EZM3, M3/PC Klagenfurt
Influenced by Modula-2+, Modula-2, Pascal, ALGOL, Oberon
Influenced Java, Python[1], Caml, C#
OS Cross-platform (multi-platform)
License Open source
Website [1]

In computer science, Modula-3 is a programming language conceived as a successor to an upgraded version of Modula-2 known as Modula-2+. While it has been influential in research circles (influencing the designs of languages such as Java, C#, and Python) it has not been adopted widely in industry. It was designed by Luca Cardelli, James Donahue, Lucille Glassman, Mick Jordan (before at the Olivetti Software Technology Laboratory), Bill Kalsow and Greg Nelson at the Digital Equipment Corporation (DEC) Systems Research Center (SRC) and the Olivetti Research Center (ORC) in the late 1980s.

Modula-3's main features are simplicity and safety while preserving the power of a systems-programming language. Modula-3 aimed to continue the Pascal tradition of type safety, while introducing new constructs for practical real-world programming. In particular Modula-3 added support for generic programming (similar to templates), multithreading, exception handling, garbage collection, object-oriented programming, partial revelation and explicit mark of unsafe code. The design goal of Modula-3 was a language that implements the most important features of modern imperative languages in quite basic forms. Thus allegedly dangerous and complicating features like multiple inheritance and operator overloading were omitted.


Historical development

The Modula-3 project started in November 1986 when Maurice Wilkes wrote to Niklaus Wirth with some ideas for a new version of Modula. Wilkes had been working at DEC just prior to this point, and had returned to England and joined Olivetti's Research Strategy Board. Wirth had already moved on to Oberon, but had no problems with Wilkes's team continuing development under the Modula name. The language definition was completed in August 1988, and an updated version in January 1989. Compilers from DEC and Olivetti soon followed, and 3rd party implementations after that.

Its design was heavily influenced by work on the Modula-2+ language in use at SRC and at the Acorn Computers Research Center (ARC, later ORC when Olivetti bought out Acorn) at the time, which was the language in which the operating system for the DEC Firefly multiprocessor VAX workstation was written and in which the Acorn Compiler for Acorn Modula-2 Extended Language (CAMEL) at ARC for the ARX operating system project of ARM based Acorn Archimedes range of computers were written. As the revised Modula-3 Report states, the language was influenced by other languages such as Mesa, Cedar, Object Pascal, Oberon and Euclid.[2]

During the 1990s, Modula-3 gained considerable currency as a teaching language, but it was never widely adopted for industrial use. Contributing to this may have been the demise of DEC, a key Modula-3 supporter (specially when it ceased to maintain it effectively any more before DEC was sold to Compaq in 1998). In any case, in spite of Modula-3's simplicity and power, it appears that there was little demand for a procedural compiled language with restricted implementation of object-oriented programming. For a time, a commercial compiler called CM3 maintained by one of the chief implementors prior at DEC SRC who was hired before DEC being sold to Compaq, an integrated development environment called Reactor and an extensible Java Virtual Machine (licensed in binary and source formats and buildable with Reactor) were offered by Critical Mass, Inc., but that company ceased active operations in 2000 and gave some of the sources of its products to elego Software Solutions GmbH. Modula-3 is now taught in universities mostly in comparative programming language courses, and its textbooks are out of print. Essentially the only corporate supporter of Modula-3 is elego Software Solutions GmbH, which inherited the sources from Critical Mass and has since made several releases of the CM3 system in source and binary form. The Reactor IDE has been open source released after several years it had not, with the new name CM3-IDE. In March 2002 elego also took over the repository of another active Modula-3 distribution, PM3, till then maintained at the École Polytechnique de Montréal but which later continued by the work on HM3 improved over the years later until it was obsoleted.


A common example of a language's syntax is the Hello world program.

 MODULE Main; 
   IO.Put("Hello World\n")
 END Main.

All programs in Modula-3 have at least a module file, while most also include an interface file that is used by clients to access data from the module. Like in other languages, a Modula-3 program must export a Main module, which can either be a file named Main.m3, or a file can call EXPORT to export the Main module.


Module file names are suggested to be the same as the actual module name, but the compiler will only warn you if they are different.

Other conventions in the syntax include naming the exported type of an interface T, since types are usually qualified by their full names, so a type T inside a module named Foo will be named Foo.T. This aides in readability. Another similar convention is naming a public object Public as in the OOP examples above.

Language features


First and foremost, all compilation units are either INTERFACE or implementation MODULEs, of one flavor or another. An interface compilation unit, beginning with the keyword INTERFACE, defines constants, types, variables, exceptions, and procedures. The implementation module, beginning with the keyword MODULE, provides the actual code, and any further constants, types, or variables needed to implement the interface. By default an implementation module will implement the interface of the same name, but a module may explicitly EXPORT to a module not of the same name. For example, the main program exports an implementation module for the Main interface.

 MODULE HelloWorld EXPORTS Main; 
   IO.Put("Hello World\n")
 END Main.

Any compilation unit may IMPORT other interfaces, and under programer control, the items contained in the interface. Typically, one only imports the interface, and uses the 'dot' notation to access the items within the interface (similar to accessing the fields within a record). A typical usage is to define one data structure (record or object) per interface along with any support procedures. Here the main type will get the name 'T', and one uses as in MyModule.T.

Safe vs Unsafe

Some capability is deemed unsafe, where the compiler can no longer guarantee the results will be consistent (for example, when interfacing to the C programming language). The keyword UNSAFE prefixed in front of INTERFACE or MODULE, may be used to tell the compiler to enable certain low level features of the language. For example, an unsafe operation is bypassing the type system using LOOPHOLE to copy the bits of an integer into a floating point REAL number.

An interface that imports an unsafe module must itself be unsafe. A safe interface may be exported by an unsafe implementation module. This is the typical usage when interfacing to external libraries, where two interfaces are built (one unsafe, the other safe).


A generic interface and its corresponding generic module, prefix the INTERFACE or MODULE keyword with GENERIC, and take as formal arguments other interfaces. Thus (like C++ templates) one can easily define and use abstract data types, but unlike C++, the granularity is at the module level. For example, one could define a GenericStack, then instantiate it with an INTEGER, REAL, or even references to Objects. An interface module would be passed to the generic interface and implementation modules as actual arguments, and the compiler will generate concrete modules.


Any identifier can be traced back to where it originated, unlike the 'include' feature of other languages. A compilation unit must import identifiers from other compilation units, using an IMPORT statement. Even enumerations make use of the same 'dot' notation as used when accessing a field of a record.

TYPE Color = {Black, Brown, Red, Orange, Yellow, Green, Blue, Violet, Gray, White};
  aColor: A.Color;  (* Uses the module name as a prefix *)
  theColor: Color;  (* Does not have the module name as a prefix *)
  anotherColor: A.Color;
  aColor := A.Color.Brown;
  theColor := Color.Red;
  anotherColor := Color.Orange;  (* Can't simply use Orange *)

Dynamic Programming

Modula-3 supports the allocation of data at runtime. There are two kinds of memory that can be allocated TRACED and UNTRACED. The difference being if the garbage collector can see it or not. NEW() is used to allocate data of either of these classes of memory. In an UNSAFE module, DISPOSE is available to free untraced memory.

Object Oriented

Object Oriented Programming techniques may be used in Modula-3, but their use is not required. Many of the other features provided in Modula-3 (modules, generics) can usually take the place of object orientation.

Object support is intentionally kept to its simplest terms. An object type (Termed a "class" in other object oriented languages) is introduced with the OBJECT declaration, which has essentially the same syntax as a RECORD declaration, although an object type is a reference type, whereas RECORDs in Modula-3 are not (similar to structs in C). Exported types are usually named T by convention, and create a separate "Public" type to expose the methods and data. For instance:

TYPE T <: Public;
  Public = OBJECT 
    getAge(): INTEGER;
    init(name: TEXT; age: INTEGER): T;
END Person.

This defines an interface Person with two types, T, and Public, which is defined as an object with two methods, getAge() and init(). T is defined as a subtype of Public by the use of the <: operator.

To create a new Person.T object, we use the built in procedure NEW with the method init() as

VAR jim := NEW(Person.T).init("Jim", 25);

Modula-3's REVEAL construct provides a conceptually simple and clean yet very powerful mechanism for hiding implementation details from clients, with arbitrarily many levels of "friendliness". We use REVEAL to show the full implementation of the Person interface from above.

MODULE Person;
  name: TEXT;   (* These two variables *)
  age: INTEGER; (* are private. *)
  getAge := Age;
  init := Init;
    RETURN self.age;
  END Age;
PROCEDURE Init(self: T; name: TEXT; age: INTEGER): T =
  BEGIN := name;
    self.age := age;
  RETURN self;
  END Init;
END Person.

Note the use of the BRANDED keyword, which "brands" objects to make them unique as to avoid structural equivalence. BRANDED can also take a string as an argument, but when omitted, a unique string is generated for you.

Modula-3 is one of the few programming languages that requires that external references from a module be strictly qualified. That is, a reference in module A to the object x exported from module B must take the form B.x. It is not possible in Modula-3 to import "all exported names" from a module.

Because of the language's requirements on name qualification and method overriding, it is impossible to break a working program simply by adding new declarations to an interface (any interface). This makes it possible for large programs to be edited concurrently by many programmers without any worries about naming conflicts; and it also makes it possible to edit core language libraries with the firm knowledge that no existing programs will be "broken" in the process.


Exception handling is based on a TRY...EXCEPT block system, which has since become common. One feature that has not been adopted in other languages, with the notable exceptions of Delphi, Python[2], Scala[3] and Visual Basic.NET, is that the EXCEPT construct defined a pseudo-CASE with each possible exception as a case in one EXCEPT clause. Modula-3 also supports a LOOP...EXIT...END construct that loops until an EXIT occurs, a structure equivalent to a simple loop inside a TRY...EXCEPT clause.


The language supports the use of multi-threading, and the synchronization between threads. The MUTEX is a built-in data structure, and the LOCK statement locks the MUTEX. The Modula-3 runtime may make use of a separate thread for garbage collection. There is a standard module within the runtime library (libm3) named Thread, which supports the use of multi-threaded applications.


In summary, the language features:

Modula-3 is one of the rare languages whose evolution of features is documented.

In Systems Programming with Modula-3, four essential points of the language design are intensively discussed. These topics are: structural vs. name equivalence, subtyping rules, generic modules, and parameter modes like READONLY.

Standard library features

Continuing a trend started with the C programming language, many of the features required to write real programs were left out of the language definition itself and instead provided via a number of standard libraries. Most of the interfaces below are described in detail in[3]

Standard libraries providing the following features. This are called standard interfaces and are required (must be provided) in the language.

  • Text: Operations on immutable string references, called TEXTs
  • Thread: Operations relating to threading, including MUTEX, condition variable, and thread pausing. The threading library provides pre-emptive threads switching
  • Word: Bitwise operations on unsigned integers (or machine words). Normally implemented directly by the compiler
  • Floating-point interfaces

Some recommended interfaces implemented in the available implementations but are not required

  • Lex: For parsing number and other data
  • Fmt: Formatting various datatypes for printing
  • Pkl (or Pickle): Object serialization of any reference types reachable by the garbage collector
  • Table: Generic modules for maps

As in C, I/O is also provided via libraries, in Modula-3 called Rd and Wr. The object-oriented design of the Rd and Wr (readers and writers respectively) libraries is covered in detail in the book by Greg Nelson. An interesting aspect of Modula-3 is that it is one of few programming languages whose standard libraries have been formally verified not to contain various types of bugs, including locking bugs. This was done under the auspices of the Larch/Modula-3 (see Larch family)[4] and Extended Static Checking[5] projects at DEC Systems Research Center.


Several compilers are available, most of them open source.

  • DEC-SRC M3, the original.[6]
  • Olivetti Research Center (ORC) Modula-3 toolkit, originally a compiler, now available as a library for syntactic, lexical and semantic analysis of Modula-3 programs.[7]
  • Critical Mass CM3, a different successor of DEC-SRC M3
  • Polytechnique Montreal Modula-3 PM3, a successor of DEC-SRC M3, currently merging with CM3
  • EzM3, an independent lightweight and easily portable implementation, developed in connection with CVSup
  • HM3, a successor of the pm3-1.1.15 release of PM3, with support of native threading using NPTL
  • CM3, the successor to Critical Mass CM3. This is the only up to date, maintained and developed implementation. Releases are available from

Since the only aspect of C data structures that is missing from Modula-3 is the union type, all existing Modula-3 implementations are able to provide good binary compatibility with C language type declarations of arrays and structs.


None of these books are still in print, although used copies are obtainable and some are digitized or partially digitized and some chapters of one them have previous or posterior versions obtainable as research reports from web.

  • Greg Nelson, ed. Systems Programming with Modula-3 The definitive reference on the Modula-3 language with interesting articles on object-oriented systems software construction and a documentation of the discussion leading to the final features of the language. There are some previously (see[2] for Chapter two,[8] for chapter four,[9] for chapter five,[10] for chapter six) and some posteriorly (see[11] for Chapter one and more updated two, thus of both previous versions of language definition[2] and,[3] for chapter three and[12] for chapter seven) of publishing versions of the majority of its eight chapters individually available from prior DEC Systems Research Center (SRC) as research reports for download.
  • Samuel P. Harbison, Modula-3 Easy to use class textbook.
  • Robert Sedgewick, Algorithms in Modula-3
  • Laszlo Boszormenyi & Carsten Weich, Programming in Modula-3: An Introduction in Programming with Style
  • Renzo Orsini, Agostino Cortesi Programmare in Modula-3 : introduzione alla programmazione imperativa e a oggetti an Italian book of the language explaining its main features.

Projects using Modula-3

  • The SPIN operating system was implemented using Modula-3 as its programming language.
  • The CVSup repository synchronization program was implemented in Modula-3.
  • The Obliq programming language which uses Modula-3 network objects ability to migrate objects over local networks transparently, allowing a distributed capability to Modula-3 object oriented programming paradigm. It has been used for building distributed applications, computer animations and web programming applications in the form of scripting extension to Modula-3.


  1. ^ Foreword for "Programming Python" (1st ed.)
  2. ^ a b c Modula-3 report (revised) Luca Cardelli, James Donahue, Lucille Glassman, Mick Jordan, Bill Kalsow, Greg Nelson. DEC Systems Research Center (SRC) Research Report 52 (November 1989)
  3. ^ a b Some Useful Modula-3 Interfaces Jim Horning, Bill Kalsow, Paul McJones, Greg Nelson. DEC Systems Research Center (SRC) Research Report 113 (December 1993)
  4. ^ LM3 Kevin D. Jones. DEC Systems Research Center (SRC) Research Report 72 (June 1991)
  5. ^ Extended Static Checking David L. Detlefs, K. Rustan M. Leino, Greg Nelson, James B. Saxe. Compaq SRC Research Report 159 (December 1998)
  6. ^ SRC Modula-3 3.3 Bill Kalsow and Eric Muller. Digital Equipment Corporation (January 1995)
  7. ^ Jordan, Mick (1990). "An extensible programming environment for Modula-3". SIGSOFT Softw. Eng. Notes 15 (6): 66–76. doi:10.1145/99278.99285. Retrieved 2009-09-08. 
  8. ^ An Introduction to Programming with Threads Andrew D. Birrell. DEC Systems Research Center (SRC) Research Report 35 (January 1989)
  9. ^ Synchronization Primitives for a Multiprocessor: A Formal Specification A. D. Birrell, J. V. Guttag, J. J. Horning, R. Levin. DEC Systems Research Center (SRC) Research Report 20 (August 1987)
  10. ^ IO Streams: Abstract Types, Real Programs Mark R. Brown and Greg Nelson. DEC Systems Research Center (SRC) Research Report 53 (November 1989)
  11. ^ Modula-3 Reference Manual Luca Cardelli, James Donahue, Lucille Glassman, Mick Jordan, Bill Kalsow, Greg Nelson. DEC Systems Research Center (SRC) (February 1995)
  12. ^ Trestle Tutorial Mark S. Manasse and Greg Nelson. DEC Systems Research Center (SRC) Research Report 69 (May 1992)

External links

Wikimedia Foundation. 2010.

Игры ⚽ Нужно сделать НИР?

Look at other dictionaries:

  • Modula-2 — Paradigm(s) imperative, structured, modular, data and method hiding Appeared in 1978 Designed by Niklaus Wirth Typing discipline strong, static Major implementations …   Wikipedia

  • Modula-2 — Modula Apparu en 1977 Auteur Niklaus Wirth Paradigme générique, procédural, impératif …   Wikipédia en Français

  • Modula-3 — Modula 2 Modula Apparu en 1977 Auteur …   Wikipédia en Français

  • Modula-II — Modula 2 Modula Apparu en 1977 Auteur …   Wikipédia en Français

  • Modula-2 — Paradigmen: imperativ, strukturiert, modular Erscheinungsjahr: 1978 Entwickler: Niklaus Wirth Einflüsse: Pascal …   Deutsch Wikipedia

  • Modula-3 — Información general Paradigma multiparadigma: imperativo, estructurado, modular Apareció en Años 1980 Diseñado por DEC y …   Wikipedia Español

  • Modula — 2 ist eine 1978 entstandene Weiterentwicklung der Programmiersprache Pascal und wurde wie diese von Niklaus Wirth entwickelt. Hauptkennzeichen von Modula 2 sind die Sprachmerkmale zur Modularisierung von Programmen. Modula 2 diente selbst später… …   Deutsch Wikipedia

  • Modula 2 — ist eine 1978 entstandene Weiterentwicklung der Programmiersprache Pascal und wurde wie diese von Niklaus Wirth entwickelt. Hauptkennzeichen von Modula 2 sind die Sprachmerkmale zur Modularisierung von Programmen. Modula 2 diente selbst später… …   Deutsch Wikipedia

  • Modula-2+ — Paradigm(s) imperative, structured, modular Appeared in 1980s Designed by DEC Systems Research Center SRC and Acorn Research Center Developer DEC Systems Research Center SRC and Acorn Research …   Wikipedia

  • Modula-2 — Desarrollador(es) Información general Paradigma Programación imperativa, Programación modular …   Wikipedia Español

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”